feat(downloads): native Patreon verify + uniform backend dispatch (plan #697)
The credential Verify button still ran gallery-dl --simulate for Patreon after the cutover — testing the wrong path (and prone to the vanity "Failed to extract campaign ID" the native resolver fixes). Wire it to the native ingester, behind a DRY dispatch so callers never branch on platform. - services/download_backends.py (new): the ONE place that knows which platforms are native vs gallery-dl. `uses_native_ingester(platform)` is the shared predicate; `verify_source_credential(...)` is the uniform probe (same (ok|None, message) contract for both backends). As a platform migrates, it moves into NATIVE_INGESTER_PLATFORMS here and BOTH download routing and verify switch together. - PatreonClient.verify_auth(campaign_id): one authenticated /api/posts fetch → True (valid) / False (401/403/HTML-login) / None (drift or network — inconclusive, not a credential verdict). - patreon_ingester.verify_patreon_credential(): resolve campaign id, then verify_auth — the verify counterpart to the download path. - patreon_resolver.resolve_campaign_id_for_source(): extracted the override / id:-URL / vanity resolution into ONE helper now shared by the download ingester and verify (download_service no longer carries its own copy + regex; −`import re`). - download_service: routes on uses_native_ingester() instead of inline `== "patreon"` (3 sites); uses the shared resolver. - api/credentials: calls verify_source_credential — no platform branch. Tests: verify_auth mapping, resolve_campaign_id_for_source (override/id:/ vanity/none), the dispatch predicate, verify_patreon_credential glue, credentials endpoint proves Patreon uses the native path (gallery-dl verify asserted not-called); repointed the gallery-dl verify test to subscribestar. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -370,3 +370,32 @@ def test_ledger_key_video_has_no_filehash():
|
||||
kind="postfile", filehash=None, post_id="p9",
|
||||
)
|
||||
assert _ledger_key(video) == "p9:clip.mp4"
|
||||
|
||||
|
||||
# --- verify_patreon_credential (the verify counterpart, plan #697) ---------
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_verify_patreon_credential_unresolvable_is_inconclusive():
|
||||
from backend.app.services.patreon_ingester import verify_patreon_credential
|
||||
|
||||
# No campaign id resolvable from a non-Patreon URL → can't test → None.
|
||||
ok, msg = await verify_patreon_credential("not-a-patreon-url", None, {})
|
||||
assert ok is None
|
||||
assert "campaign id" in msg.lower()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_verify_patreon_credential_delegates_to_client(monkeypatch):
|
||||
import backend.app.services.patreon_ingester as mod
|
||||
|
||||
async def _fake_resolve(url, cookies_path, overrides):
|
||||
return "123", None
|
||||
monkeypatch.setattr(mod, "resolve_campaign_id_for_source", _fake_resolve)
|
||||
monkeypatch.setattr(
|
||||
mod.PatreonClient, "verify_auth",
|
||||
lambda self, campaign_id: (True, f"ok:{campaign_id}"),
|
||||
)
|
||||
ok, msg = await mod.verify_patreon_credential("https://patreon.com/x", None, {})
|
||||
assert ok is True
|
||||
assert msg == "ok:123"
|
||||
|
||||
Reference in New Issue
Block a user