"use server"; // WAYBACK PAGES (release 37 S1): one capture imported into a Wayback pages // channel (`import-page`), and the channel's records re-derived from its stored // captures (`reextract-pages`) — the controllers' own refusals, before a job // exists, in their own sentences (common/controller/importPage.ts, // reextractPages.ts). Both run on the archive.org queue. import { safeRevalidate } from "../../lib/safeRevalidate"; import { getPaths } from "yt-dlp-transcript-common/lib/paths"; import type { StreamActionResult } from "yt-dlp-transcript-common/jobs/streamCommand"; import { importPage, queueImportPage, type ImportPageResult } from "yt-dlp-transcript-common/controller/importPage"; import { queueReextractPages } from "yt-dlp-transcript-common/controller/reextractPages"; import { archiveLookup, type ArchiveLookup } from "yt-dlp-transcript-common/lib/archives/index"; import { isArchiveSourceId, type ArchiveSourceId } from "yt-dlp-transcript-common/lib/archives/types"; // Release 37 lane F: `source` ("archive.today") with a page's own URL and // `at`; a copy's URL (Wayback or archive.today) names its source itself. export async function importPageAction( slug: string, url: string, at?: string, requestedBy?: string, source?: string, ): Promise { return queueImportPage({ paths: getPaths(), slug, url: url.trim(), ...(at?.trim() ? { at: at.trim() } : {}), ...(source?.trim() ? { source: source.trim() } : {}), ...(requestedBy ? { requestedBy } : {}), onDone: () => safeRevalidate([`/channels/${slug}`]), }); } // What an import WOULD fetch, answered now (no job, no request). export async function importPageDryRunAction(slug: string, url: string, at?: string, source?: string): Promise { return importPage({ paths: getPaths(), slug, url: url.trim(), ...(at?.trim() ? { at: at.trim() } : {}), ...(source?.trim() ? { source: source.trim() } : {}), dryRun: true, }); } // THE COPIES OF A PAGE across archive sources (release 37 lane F, // `archive-lookup`): read only, each source through its own paced client; a // source that refuses (excluded, a check, a 429) is its own entry's sentence. export async function archiveLookupAction( url: string, source?: string, limit?: number, ): Promise<{ ok: true; lookup: ArchiveLookup } | { ok: false; error: string }> { const given = url.trim(); if (!/^https?:\/\/[^\s]+$/.test(given)) return { ok: false, error: "give a page's own http(s) URL" }; if (source && !isArchiveSourceId(source)) return { ok: false, error: `"source" must be "wayback" or "archive.today", not "${source}"` }; const lookup = await archiveLookup(given, { ...(source ? { source: source as ArchiveSourceId } : {}), limit: Math.min(Math.max(1, limit ?? 50), 500), }); return { ok: true, lookup }; } export async function reextractPagesAction(slug: string, dryRun?: boolean): Promise { return queueReextractPages({ paths: getPaths(), slug, ...(dryRun ? { dryRun: true } : {}) }); }