import { WAYBACK_SCAN_BODY_KEYS } from "yt-dlp-transcript-common/controller/waybackScan"; import { waybackScanAction } from "../../../channels/[slug]/captures/actions"; import { jobResponse, ops, optBool, optPositiveInt, reqSlug } from "../_lib"; export const dynamic = "force-dynamic"; // POST { slug, dryRun?, maxRows?, full? } -> { ok: true, jobId } // // A Wayback pages channel's scan (release 37 S2), as a `wayback-scan` job on // archive.org's queue: the CDX listing of every target in its // `config.wayback.targets` (matchType per target, status 200, its mimes, // collapse=digest, its date bounds), in pages of 5,000, at most `maxRows` // (50,000, at most 200,000) a run, into `channels//wayback-scan.json` — // one row per distinct (URL, digest) with first/last seen. No bodies. A run cut // short keeps each target's resume key and the next continues; once every // target is complete the next run is a new pass (from 30 days before the last // began); `full` starts a new pass from each target's start. Paced as // archive.org asks (one at a time, 2 s apart, 429/503 waited out; a refusal // stops the job and keeps the resume key). `dryRun` asks nothing and writes // nothing: it logs what the next run would ask. Refused before any job for a // channel with no `wayback.targets`. The log ends `@@wayback-scan {slug, // dryRun, pass, newPass, targets: [{url, match, requests, rows, added, // complete, resumeKey?, next?}], requests, rowsRead, added, totalRows, // complete, stopped?, error?, excluded?}`. A target the Wayback Machine // answers 403 for is EXCLUDED (release 38 lane C): its report carries // `refusal: "excluded"` and "excluded from the Wayback Machine (cause // unknown)", it is done for this pass, and the run goes on to the next target. // // AN ADAPTER: the refusals are the controller's (controller/waybackScan.ts). export async function POST(request: Request) { return ops(request, WAYBACK_SCAN_BODY_KEYS, async (body) => { const slug = reqSlug(body, "slug"); const maxRows = optPositiveInt(body, "maxRows"); return jobResponse( await waybackScanAction(slug, { dryRun: optBool(body, "dryRun") === true, full: optBool(body, "full") === true, ...(maxRows !== undefined ? { maxRows } : {}), }), ); }); }