fix: address whole-branch review findings for update-swarm
- versions: require entire normalized string to be numeric so dates and hotfix suffixes compare as incomparable instead of eq/gt - hosts: exact host or dot-suffix match rejects lookalikes like notmediafire.com and evilmega.nz; GitHub stays exact-set - census: lazy extractor loop so a later OSError no longer discards an earlier sidecar changelog hit - jobs: watchlist parses only table rows whose vault-note cell is a bare wikilink (skips parenthetical related/complete notes); wanted also matches bold names in Wanted.md tables with Pokemon prefix stripped and casefolded - cli: validate-scouts and judge raise SystemExit when jobs.json has jobs but scouts/ has zero valid files - fetch: download forwards timeout=60 to urlopen and writes to a .part file then os.replace, removing the partial on any failure
This commit is contained in:
1 parent
37ebc97b51
commit
cb294f72a0
16 files changed
+234
-48
No files matched your search
@@ -1,30 +1,40 @@
|
||||
from __future__ import annotations
|
||||
from urllib.parse import urlparse
|
||||
|
||||
GITHUB_HOSTS = frozenset(("github.com", "raw.githubusercontent.com", "objects.githubusercontent.com"))
|
||||
# Exact host or dot-suffix match — `endswith(d)` alone accepts lookalikes like
|
||||
# `notmediafire.com` or `evilmega.nz`.
|
||||
SUFFIX_HOSTS = {
|
||||
"archive.org": "archive",
|
||||
"mediafire.com": "mediafire",
|
||||
"mega.nz": "mega",
|
||||
"mega.co.nz": "mega",
|
||||
"itch.io": "itch",
|
||||
"ko-fi.com": "kofi",
|
||||
"hackdex.app": "hackdex",
|
||||
"pokecommunity.com": "pokecommunity",
|
||||
}
|
||||
|
||||
def _host_match(host: str, domain: str) -> bool:
|
||||
return host == domain or host.endswith("." + domain)
|
||||
|
||||
def classify_url(url: str) -> tuple[str, str]:
|
||||
p = urlparse(url or "")
|
||||
host = (p.netloc or "").lower().removeprefix("www.")
|
||||
path = p.path or ""
|
||||
if host in ("github.com", "raw.githubusercontent.com", "objects.githubusercontent.com"):
|
||||
if host in GITHUB_HOSTS:
|
||||
if host != "github.com" or "/releases/download/" in path:
|
||||
return "github", "ungated"
|
||||
return "github", "gated"
|
||||
if host.endswith("archive.org"):
|
||||
return "archive", "ungated"
|
||||
if host.endswith("mediafire.com"):
|
||||
return "mediafire", "ungated"
|
||||
if host.endswith("mega.nz") or host.endswith("mega.co.nz"):
|
||||
return "mega", "ungated" if p.fragment else "gated"
|
||||
if host.endswith("itch.io"):
|
||||
return "itch", "gated"
|
||||
for domain, label in SUFFIX_HOSTS.items():
|
||||
if _host_match(host, domain):
|
||||
if label == "mega":
|
||||
return "mega", "ungated" if p.fragment else "gated"
|
||||
if label in ("archive", "mediafire"):
|
||||
return label, "ungated"
|
||||
return label, "gated"
|
||||
if host in ("drive.google.com", "docs.google.com"):
|
||||
return "drive", "gated"
|
||||
if host in ("discord.com", "discord.gg"):
|
||||
return "discord", "gated"
|
||||
if host.endswith("ko-fi.com"):
|
||||
return "kofi", "gated"
|
||||
if host.endswith("hackdex.app"):
|
||||
return "hackdex", "gated"
|
||||
if host.endswith("pokecommunity.com"):
|
||||
return "pokecommunity", "gated"
|
||||
return "other", "gated"
|
||||
Reference in new issue
Block a user