diff --git a/backend/app/services/download_backends.py b/backend/app/services/download_backends.py index 350f009..48e6ceb 100644 --- a/backend/app/services/download_backends.py +++ b/backend/app/services/download_backends.py @@ -34,18 +34,22 @@ from .subscribestar_ingester import SubscribeStarIngester # deviantart) until they migrate too. NATIVE_INGESTER_PLATFORMS = frozenset({"patreon", "subscribestar"}) -# Native ingester classes keyed by platform (uniform constructor signature, so -# _run_native_ingester / preview build whichever the source needs). -_NATIVE_INGESTERS = { - "patreon": PatreonIngester, - "subscribestar": SubscribeStarIngester, -} - # Mirrors patreon_resolver._CAMPAIGNS_URL — surfaced in resolution-failure # messages so the operator sees the exact lookup endpoint that was hit. _CAMPAIGNS_API = "https://www.patreon.com/api/campaigns" +def _native_ingester_cls(platform: str): + """The native ingester class for `platform` (uniform constructor signature). + A call-time lookup (not a module-level dict captured at import) so tests can + monkeypatch db_mod.PatreonIngester / SubscribeStarIngester and have the + dispatch pick up the replacement.""" + return { + "patreon": PatreonIngester, + "subscribestar": SubscribeStarIngester, + }[platform] + + def uses_native_ingester(platform: str) -> bool: """True when `platform` is served by the native ingester (not gallery-dl). The single predicate the download path and verify both route on.""" @@ -150,7 +154,7 @@ async def _run_native_ingester( if source_config.sleep_request is not None else max(0.5, rate_limit / 4) ) - ingester = _NATIVE_INGESTERS[platform]( + ingester = _native_ingester_cls(platform)( images_root=gdl.images_root, cookies_path=ctx["cookies_path"], session_factory=sync_session_factory, @@ -209,7 +213,7 @@ async def preview_source( "(cookies expired, or the creator moved/renamed?)." ) } - ingester = _NATIVE_INGESTERS[platform]( + ingester = _native_ingester_cls(platform)( images_root=images_root, cookies_path=cookies_path, session_factory=sync_session_factory,