"use client"; // A Wayback pages channel's targets as editable rows (release 37): a URL, how // it matches, and optional capture-date bounds. Posted as ONE hidden field, // `waybackTargets` (a JSON array), which parseChannelForm validates. import { useEffect, useState } from "react"; import { WAYBACK_TARGET_MATCHES, waybackTargetFromUrl, type WaybackTarget, } from "yt-dlp-transcript-common/lib/waybackPages/config"; // `sources` (release 37 lane F): "wayback", "archive.today" or "both" — // where the target's copies are looked for. // `keep`: what the rows do not edit (mime, include, exclude), carried through a // save so the scan's filters survive an edit of the form (release 37 S2). type Row = { url: string; match: string; from: string; to: string; sources?: string; keep?: Pick; }; const SOURCE_LABELS: Record = { wayback: "Wayback Machine", "archive.today": "archive.today", both: "Both", }; const sourcesOf = (t: WaybackTarget): string => { const s = t.sources ?? []; if (s.includes("wayback") && s.includes("archive.today")) return "both"; if (s.includes("archive.today")) return "archive.today"; return "wayback"; }; const sourcesList = (v: string | undefined): string[] | undefined => v === "both" ? ["wayback", "archive.today"] : v === "archive.today" ? ["archive.today"] : undefined; const LABELS: Record = { exact: "Exact page", prefix: "Prefix (every URL under it)", host: "Host", domain: "Domain (and subdomains)", }; const toRow = (t: WaybackTarget): Row => { const keep = { ...(t.mime?.length ? { mime: t.mime } : {}), ...(t.include ? { include: t.include } : {}), ...(t.exclude ? { exclude: t.exclude } : {}), }; return { url: t.url, match: t.match, from: t.from ?? "", to: t.to ?? "", sources: sourcesOf(t), ...(Object.keys(keep).length ? { keep } : {}) }; }; export function WaybackTargetsField({ initial, derivedFrom, auto, }: { // `wayback.auto` (release 37 S2): the download lane imports the captures a // later scan adds. Posted as the `waybackAuto` checkbox. auto?: boolean; // The stored targets (edit mode). initial?: WaybackTarget[]; // Create mode: the URL typed above, a first row is derived from until a row // is edited by hand. derivedFrom?: string; }) { const [rows, setRows] = useState(initial?.length ? initial.map(toRow) : []); const [touched, setTouched] = useState(!!initial?.length); useEffect(() => { if (touched || derivedFrom === undefined) return; const t = waybackTargetFromUrl(derivedFrom); setRows(t ? [toRow(t)] : []); }, [derivedFrom, touched]); const edit = (i: number, patch: Partial) => { setTouched(true); setRows((rs) => rs.map((r, j) => (j === i ? { ...r, ...patch } : r))); }; const value = JSON.stringify( rows .filter((r) => r.url.trim()) .map((r) => ({ url: r.url.trim(), match: r.match, ...(r.from.trim() ? { from: r.from.trim() } : {}), ...(r.to.trim() ? { to: r.to.trim() } : {}), ...(sourcesList(r.sources) ? { sources: sourcesList(r.sources) } : {}), ...(r.keep ?? {}), })), ); const input = "rounded border border-border bg-card px-2 py-1 text-sm"; return (
Targets {rows.map((r, i) => (
edit(i, { url: e.target.value })} aria-label={`target ${i + 1} URL`} placeholder="example.com/blog" className={`${input} flex-1 font-mono`} /> edit(i, { from: e.target.value })} aria-label={`target ${i + 1} from`} placeholder="from (2014)" className={`${input} w-28 font-mono`} /> edit(i, { to: e.target.value })} aria-label={`target ${i + 1} to`} placeholder="to (2016)" className={`${input} w-28 font-mono`} />
))}
Which captures are in scope, and on which archive. Dates are capture timestamps or their start (2014, 201403, 20140305).
); }