The browser extension (poli0981/itch-f2p-extension) and the Telegram bot (poli0981/telegram-scraper-bot) are archived. Removed: POST /api/ingest (ingest.ts, requireService, the idempotency store, RL_INGEST, ACCESS_AUD_INGEST; it never received a game), the admin's "Browser extension" auto-approve source and "Extension" queue label, and the About page's Telegram numeric-ID note. No D1 migration: the idempotency table and the 'ext' CHECK stay. Policies (Privacy, ToS, EULA + installer RTF, Disclaimer, Security; EN + VI) drop the extension / ingest wording; Last updated 2026-10-16, LEGAL_VERSION unchanged. Docs, CLAUDE.md and pipeline comments updated. Release 4.4.1 (also ships #131, #135, #136, #137). [skip-discuss] Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
84 lines
2.9 KiB
Python
84 lines
2.9 KiB
Python
"""
|
|
patch.py — The hand-off format between pipeline scans and the commit step.
|
|
|
|
Scanners (refresh.py, update_info.py) never write the catalog directly. They
|
|
emit a patch; apply_patch.py applies it idempotently to whatever `main` looks
|
|
like at push time, so concurrent writers (other workflows, the admin Worker
|
|
and its cron) never overwrite each other.
|
|
|
|
Patch v1:
|
|
{
|
|
"version": 1,
|
|
"kind": "refresh" | "full" | "ingest",
|
|
"generated_at": "<iso>",
|
|
"additions": [<full game record>, ...], # appended if URL absent
|
|
"updates": {"<url>": {"<field>": <value>}}, # scraper-owned fields only
|
|
"removals": [{"url", "name", "reason", "deleted_at"}],
|
|
"refresh_state": {"<url>": {...} | null}, # null = drop entry
|
|
"ingest_state": {"<url>": {...} | null},
|
|
"ingest_outcomes": {"<url>": {"outcome", "at"}}, # how a queued link ended (added, paid,
|
|
# dead, private, duplicate, deleted, gave_up)
|
|
"queue_add": ["<url>", ...], # append to temp_link.json if absent
|
|
"queue_remove": ["<url>", ...], # drop from temp_link.json
|
|
"unlog": ["<url>", ...], # unblocked + re-added: drop from the
|
|
# deleted log and state/unblocked.json
|
|
"unblock_remove": ["<url>", ...], # unblocked, ended otherwise: drop from
|
|
# state/unblocked.json only
|
|
"stats": {...} # informational
|
|
}
|
|
"""
|
|
|
|
from json_io import dumps, load_json, write_text_if_changed
|
|
from scraper import now_iso
|
|
|
|
PATCH_VERSION = 1
|
|
|
|
|
|
def new_patch(kind: str) -> dict:
|
|
return {
|
|
"version": PATCH_VERSION,
|
|
"kind": kind,
|
|
"generated_at": now_iso(),
|
|
"additions": [],
|
|
"updates": {},
|
|
"removals": [],
|
|
"refresh_state": {},
|
|
"ingest_state": {},
|
|
"ingest_outcomes": {},
|
|
"queue_add": [],
|
|
"queue_remove": [],
|
|
"unlog": [],
|
|
"unblock_remove": [],
|
|
"stats": {},
|
|
}
|
|
|
|
|
|
def write_patch(path: str, patch: dict) -> None:
|
|
"""Atomic write, so a job killed mid-checkpoint still leaves a valid patch."""
|
|
write_text_if_changed(path, dumps(patch))
|
|
|
|
|
|
def load_patch(path: str) -> dict:
|
|
patch = load_json(path, default={})
|
|
if patch.get("version") != PATCH_VERSION:
|
|
raise ValueError(f"{path}: unsupported patch version {patch.get('version')!r}")
|
|
return patch
|
|
|
|
|
|
def is_empty(patch: dict) -> bool:
|
|
return not any(
|
|
patch.get(k)
|
|
for k in (
|
|
"additions",
|
|
"updates",
|
|
"removals",
|
|
"refresh_state",
|
|
"ingest_state",
|
|
"ingest_outcomes",
|
|
"queue_add",
|
|
"queue_remove",
|
|
"unlog",
|
|
"unblock_remove",
|
|
)
|
|
)
|