// `archilyzer wayback pages import [--at YYYYMMDD] [--source archive.today] [--dry-run]` // and `archilyzer wayback pages reextract [--dry-run]` — a Wayback pages // channel (release 37 S1) from the command line, in-process. // // import ONE capture (controller/importPage.ts), through this process's // own polite Wayback client (one stream, the 2 s gap). While an // editor runs, prefer `pnpm ops import-page` — its imports share // the editor's one archive.org queue; this command does not. // reextract every record re-derived from the stored captures // (controller/reextractPages.ts), no request. It writes the // channel's posts: run it with the editor stopped, or use // `pnpm ops reextract-pages` / the channel page's Re-extract, // which queue it beside the channel's imports. import { isValidChannelSlug } from "../controller/channels"; import { importPage } from "../controller/importPage"; import { reextractPages } from "../controller/reextractPages"; import { getPaths, type Paths } from "../lib/paths"; export async function importMain(opts: { slug: string; url: string; at?: string; source?: string; dryRun: boolean; paths?: Paths; signal?: AbortSignal; }): Promise { if (!isValidChannelSlug(opts.slug)) { console.error(`wayback pages import: "${opts.slug}" is not a channel slug`); return 2; } const r = await importPage({ paths: opts.paths ?? getPaths(), slug: opts.slug, url: opts.url, ...(opts.at ? { at: opts.at } : {}), ...(opts.source ? { source: opts.source } : {}), dryRun: opts.dryRun, onLog: (line) => console.log(line), ...(opts.signal ? { signal: opts.signal } : {}), }); if (!r.ok) { console.error(`wayback pages import: ${r.error}`); return 1; } if (r.dryRun) console.log(`dry run: would fetch ${r.wouldFetch}`); else if (r.already) console.log(`already stored: ${r.captureTs} of ${r.originalUrl}`); else console.log(`imported ${r.captureTs} of ${r.originalUrl}: ${r.records?.length ?? 0} record(s), ${r.written} new, ${r.updated} updated.`); return 0; } export async function reextractMain(opts: { slug: string; dryRun: boolean; paths?: Paths }): Promise { if (!isValidChannelSlug(opts.slug)) { console.error(`wayback pages reextract: "${opts.slug}" is not a channel slug`); return 2; } const r = await reextractPages({ paths: opts.paths ?? getPaths(), slug: opts.slug, dryRun: opts.dryRun, onLog: (line) => console.log(line), }); if (!r.ok) { console.error(`wayback pages reextract: ${r.error}`); return 1; } return 0; } // `archilyzer archive lookup ` (release 37 lane F): the copies each archive // source holds of a page, read only. export async function lookupMain(opts: { url: string; source?: string; limit?: number }): Promise { const { archiveLookup } = await import("../lib/archives/index"); const { isArchiveSourceId } = await import("../lib/archives/types"); if (opts.source && !isArchiveSourceId(opts.source)) { console.error(`archive lookup: --source must be "wayback" or "archive.today", not "${opts.source}"`); return 2; } const limit = opts.limit && Number.isInteger(opts.limit) && opts.limit > 0 ? Math.min(opts.limit, 500) : 50; const r = await archiveLookup(opts.url, { ...(opts.source ? { source: opts.source as "wayback" | "archive.today" } : {}), limit }); for (const s of r.sources) { if (!s.ok) { console.log(`${s.label}: ${s.error}`); continue; } console.log(`${s.label}: ${s.captures.length} cop${s.captures.length === 1 ? "y" : "ies"}`); for (const c of s.captures) console.log(` ${c.captureTs} ${c.mementoUrl}`); } return r.sources.some((s) => s.ok) ? 0 : 1; }