"use client"; // A WAYBACK PAGES channel's page (release 37 S1): what it holds, the scope its // targets name, one capture imported by its URL (`import-page`), and the // records re-derived from the stored captures (`reextract-pages`). No fetch: // captures are chosen, one job each, at archive.org's pace. import { useState } from "react"; import Link from "next/link"; import { StreamActionLog } from "yt-dlp-transcript-common/components/StreamActionLog"; import { cancelJobAction } from "../../../jobs/actions"; import { archiveLookupAction, importPageAction, reextractPagesAction } from "../waybackPagesActions"; import { WaybackPageRecords, type WaybackPageRecordRow } from "./WaybackPageRecords"; import { ConnectArchiveSession } from "../../../settings/components/ArchiveSessionSection"; import type { ArchiveSessionStatus } from "yt-dlp-transcript-common/lib/archives/archiveTodaySession"; import type { ArchiveLookup } from "yt-dlp-transcript-common/lib/archives/index"; import { archiveSourceLabel, isArchiveTodayUrl } from "yt-dlp-transcript-common/lib/archives/mementos"; // A record's row: its capture's view and its shot (WaybackPageRecords.tsx). export type WaybackPagesRecordRow = WaybackPageRecordRow; export type WaybackPagesState = { recordCount: number; captureCount: number; targets: { url: string; match: string; from?: string; to?: string; sources?: string[] }[]; recent: WaybackPagesRecordRow[]; // Release 37 lane F: archive.today's check, passed once in Connect. archiveSession?: ArchiveSessionStatus; }; const MATCH_LABEL: Record = { exact: "this page", prefix: "every URL under", host: "the host", domain: "the domain", }; // "2014-03-05" → "20140305"; anything else as typed (the controller refuses // what is not a date). function atFromDate(v: string): string { return /^\d{4}-\d{2}-\d{2}$/.test(v) ? v.replaceAll("-", "") : v.trim(); } export function WaybackPagesPanel({ slug, state }: { slug: string; state: WaybackPagesState }) { const [url, setUrl] = useState(""); const [date, setDate] = useState(""); // Release 37 lane F: where the capture nearest a date is looked for (a // copy's URL names its own source). const [source, setSource] = useState("wayback"); const [importJob, setImportJob] = useState(null); const [reextractJob, setReextractJob] = useState(null); const input = "rounded border border-border bg-card px-2 py-1 text-sm font-mono"; return (

Pages

Captures: scan and choose {state.recordCount} record{state.recordCount === 1 ? "" : "s"} from {state.captureCount} capture {state.captureCount === 1 ? "" : "s"}
{state.targets.length > 0 && (
    {state.targets.map((t, i) => (
  • {MATCH_LABEL[t.match] ?? t.match} {t.url} {t.from || t.to ? ( · captured {t.from ?? "…"}–{t.to ?? "…"} ) : null} {t.sources?.length ? ( · on {t.sources.map((x) => archiveSourceLabel(x)).join(" and ")} ) : null}
  • ))}
)} {state.recent.length > 0 && }

Import a capture

setUrl(e.target.value)} aria-label="capture URL" placeholder="https://web.archive.org/web/20140305120000/https://… or https://archive.ph/…" className={`${input} w-[36rem] max-w-full`} /> importPageAction( slug, url.trim(), date ? atFromDate(date) : undefined, undefined, date && source !== "wayback" && !isArchiveTodayUrl(url) ? source : undefined, ) } cancelAction={cancelJobAction} buttonLabel="Import capture" runningLabel="Importing…" label={`Import a capture into ${slug}`} disabled={!url.trim()} onSettled={(started, out) => setImportJob(started ? out.jobId : null)} /> {importJob && ( Open the import job )}
{state.archiveSession && (

archive.today check

)}

Re-extract

Every record read again from the stored captures; nothing is fetched. reextractPagesAction(slug)} cancelAction={cancelJobAction} buttonLabel="Re-extract" runningLabel="Re-extracting…" label={`Re-extract pages of ${slug}`} disabled={state.captureCount === 0} onSettled={(started, out) => setReextractJob(started ? out.jobId : null)} /> {reextractJob && ( Open the re-extract job )}
); } // LOOK UP A PAGE across archive sources (release 37 lane F, `archive-lookup`): // the copies each source holds, read only; each row imports that one copy. function ArchiveLookupSection({ slug }: { slug: string }) { const [page, setPage] = useState(""); const [lookup, setLookup] = useState(null); const [error, setError] = useState(null); const [busy, setBusy] = useState(false); const [jobs, setJobs] = useState>({}); const [refusals, setRefusals] = useState>({}); const input = "rounded border border-border bg-card px-2 py-1 text-sm font-mono"; return (

Look up a page

setPage(e.target.value)} aria-label="page URL" placeholder="https://… (the page's own URL)" className={`${input} w-[30rem] max-w-full`} />
{error && ( {error} )} {lookup && lookup.sources.map((s) => (
{s.label}: {s.ok ? `${s.captures.length} cop${s.captures.length === 1 ? "y" : "ies"}` : s.error} {s.captures.length > 0 && (
    {s.captures.map((c) => (
  • {c.captureTs} {c.status ?? ""} {jobs[c.mementoUrl] ? ( import job ) : ( )} {refusals[c.mementoUrl] && {refusals[c.mementoUrl]}}
  • ))}
)}
))}
); }