mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-23 18:17:53 -06:00
refactor: route network access through upstream
Branch heads (scrapers, FBNeo import, data directories) resolve through core.upstream.resolve_head, with cache_dir=None to keep nothing under .cache/upstream. Streaming downloads (large files, external pack files, data directory archives, scraper downloads, standalone probe) go through one core.upstream.download: scratch then rename, size cap, retries of a cut stream, a 5xx or a rate limit. The shared rate limit wait reads GoatCounter's X-Rate-Limit-Reset, so site insights, download.py, indexnow and the contributor list use the same retrying client. list_gitlinks raises TruncatedListingError on a partial tree, read from one tree walk shared with list_tree (Forgejo paging included). The Recalbox configs/ listing is paged with the shared page cap.
This commit is contained in:
1 parent
526d7f09c7
commit
8a8fa71fbc
25 files changed
+708
-266
No files matched your search
@@ -39,7 +39,6 @@ import sys
|
||||
import tempfile
|
||||
import threading
|
||||
import time
|
||||
import urllib.request
|
||||
from collections.abc import Sequence
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
@@ -48,6 +47,7 @@ from typing import IO
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
||||
|
||||
import core_probe as cp
|
||||
from core import upstream
|
||||
from core.statefile import now_iso
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
@@ -230,12 +230,10 @@ def parse_xwd(data: bytes) -> tuple[int, int, bytes]:
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
def github_releases(repo: str) -> list[dict]:
|
||||
from scraper.base_scraper import github_headers
|
||||
from scraper.base_scraper import github_json
|
||||
|
||||
request = urllib.request.Request(f"https://api.github.com/repos/{repo}/releases",
|
||||
headers=github_headers())
|
||||
with urllib.request.urlopen(request, timeout=60) as response:
|
||||
return json.load(response)
|
||||
return github_json(f"https://api.github.com/repos/{repo}/releases",
|
||||
f"cannot list the releases of {repo}", timeout=60)
|
||||
|
||||
|
||||
def fetch(emu: Emulator, cache: Path = CACHE) -> dict:
|
||||
@@ -246,8 +244,8 @@ def fetch(emu: Emulator, cache: Path = CACHE) -> dict:
|
||||
folder = cache / emu.name
|
||||
folder.mkdir(parents=True, exist_ok=True)
|
||||
partial = folder / f"{asset['name']}.part"
|
||||
with urllib.request.urlopen(asset["url"], timeout=600) as response, partial.open("wb") as out:
|
||||
shutil.copyfileobj(response, out)
|
||||
# Whole or absent, retried on a cut stream (core.upstream.download).
|
||||
upstream.download(asset["url"], partial, timeout=600)
|
||||
sha256 = cp.file_digest(partial, "sha256")
|
||||
target = folder / sha256 / asset["name"]
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
Reference in new issue
Block a user