Subscriptions UX overhaul + Patreon /cw/ vanity fix #75

Merged
bvandeusen merged 3 commits from dev into main 2026-06-06 21:12:02 -04:00
2 changed files with 29 additions and 5 deletions
Showing only changes of commit c65da42593 - Show all commits
+15 -5
View File
@@ -30,9 +30,17 @@ _CAMPAIGNS_URL = "https://www.patreon.com/api/campaigns"
# A source URL of the form `.../id:<digits>` already carries the campaign id
# (no lookup needed). The vanity regex deliberately EXCLUDES the id: form so the
# two paths don't overlap.
#
# Patreon serves the creator vanity under several path prefixes — bare
# (`patreon.com/Atole`), `c/` (`patreon.com/c/Atole`), and `cw/`
# (`patreon.com/cw/Atole`, its current "creator workspace" URL). The optional
# prefix group must list `cw/` BEFORE `c/` so the longer prefix wins — otherwise
# `cw/Atole` matches the bare branch and yields vanity="cw" (operator-flagged
# 2026-06-07: every `/cw/` source failed resolution on vanity="cw").
_ID_URL_RE = re.compile(r"/id:(\d+)")
_VANITY_PREFIXES = ("cw/", "c/")
_VANITY_RE = re.compile(
r"^https?://(?:www\.)?patreon\.com/(?:c/)?(?!id:)([^/?#]+)",
r"^https?://(?:www\.)?patreon\.com/(?:cw/|c/)?(?!id:)([^/?#]+)",
re.IGNORECASE,
)
_USER_AGENT = (
@@ -141,10 +149,12 @@ def _lookup_via_page(vanity: str, cookies_path: str | None) -> str | None:
Patreon redirects between. Never raises."""
jar = _load_cookie_jar(cookies_path)
headers = {"User-Agent": _USER_AGENT, "Accept": "text/html"}
for page_url in (
f"https://www.patreon.com/{vanity}",
f"https://www.patreon.com/c/{vanity}",
):
# Try the bare vanity and every known creator-path prefix Patreon
# redirects between (c/, cw/) — the one the source used isn't known here
# (extract_vanity already stripped it).
page_urls = [f"https://www.patreon.com/{vanity}"]
page_urls += [f"https://www.patreon.com/{p}{vanity}" for p in _VANITY_PREFIXES]
for page_url in page_urls:
try:
resp = requests.get(
page_url,
+14
View File
@@ -169,3 +169,17 @@ async def test_for_source_unresolvable_returns_none():
cid, resolved = await resolve_campaign_id_for_source("not-a-patreon-url", None, {})
assert cid is None
assert resolved is None
def test_extract_vanity_handles_all_path_prefixes():
"""Patreon serves the vanity bare and under c/ and cw/ prefixes; all must
yield the creator slug, not the prefix (operator-flagged 2026-06-07: a
/cw/Atole source resolved vanity='cw')."""
from backend.app.services.patreon_resolver import extract_vanity
assert extract_vanity("https://www.patreon.com/Atole") == "Atole"
assert extract_vanity("https://www.patreon.com/c/Atole") == "Atole"
assert extract_vanity("https://www.patreon.com/cw/Atole") == "Atole"
assert extract_vanity("https://patreon.com/cw/Atole") == "Atole"
# id: URLs are NOT vanities (handled by the id path).
assert extract_vanity("https://www.patreon.com/id:123") is None