"use server"; // WAYBACK PAGES, LIVE (release 37 S5): Save Page Now — "Ask the Wayback // Machine to capture this now" (controller/savePageNow.ts) — and find-copy's // page mode, a copy of every gone page a report cites (publish/findCopyPages.ts). // Both on the archive.org queue; the controllers' refusals in their own // sentences, before a job exists. The original-URL availability check is the // posts' own action (socialActions.ts checkPostAvailabilityAction). import { safeRevalidate } from "../../lib/safeRevalidate"; import { getPaths } from "yt-dlp-transcript-common/lib/paths"; import { getSite, isValidSiteId, listSiteIds } from "yt-dlp-transcript-common/lib/site"; import { articlesWorkHost, siteReportHost, type ReportHost } from "yt-dlp-transcript-common/publish/reportHost"; import { runManagedFunction, type StreamActionResult } from "yt-dlp-transcript-common/jobs/streamCommand"; import { queueSavePageNow, savePageNow, savePageNowAvailability, type SavePageNowAvailability, type SavePageNowResult, } from "yt-dlp-transcript-common/controller/savePageNow"; import { WAYBACK_PAGES_QUEUE } from "yt-dlp-transcript-common/controller/importPage"; import { queueSpnBatch, spnBatchDryRun, type SpnBatchRequest } from "yt-dlp-transcript-common/controller/savePageNowBatch"; import { findPageCopies } from "yt-dlp-transcript-common/publish/findCopyPages"; import { FIND_COPY_RESULT_MARKER } from "yt-dlp-transcript-common/publish/findCopy"; import { readChannelConfig } from "yt-dlp-transcript-common/controller/channels"; import { isWaybackPagesChannel } from "yt-dlp-transcript-common/lib/waybackPages/config"; export async function savePageNowAction(url: string, slug?: string, requestedBy?: string): Promise { return queueSavePageNow({ paths: getPaths(), url: url.trim(), ...(slug?.trim() ? { slug: slug.trim() } : {}), ...(requestedBy ? { requestedBy } : {}), onDone: () => { if (slug) safeRevalidate([`/channels/${slug}`]); }, }); } // SAVE PAGE NOW, A LIST (lane spn-batch): one resumable save-page-now-batch // job (controller/savePageNowBatch.ts), or — dryRun — the plan answered now. export async function savePageNowBatchAction(req: SpnBatchRequest, requestedBy?: string): Promise { return queueSpnBatch({ paths: getPaths(), req, ...(requestedBy ? { requestedBy } : {}) }); } export async function savePageNowBatchDryRunAction(req: SpnBatchRequest) { return spnBatchDryRun(getPaths(), req); } // What a capture WOULD ask, answered now (no job, no request). export async function savePageNowDryRunAction(url: string, slug?: string): Promise { return savePageNow({ paths: getPaths(), url: url.trim(), ...(slug?.trim() ? { slug: slug.trim() } : {}), dryRun: true }); } // Whether the button is on, and why not (the keys' presence, never their // value). export async function savePageNowAvailabilityAction(): Promise { return savePageNowAvailability(); } // FIND-COPY, PAGE MODE: `{article} | {articles: true} | {siteId}`, `channel?`, // `max?`, `dryRun?` — one find-copy job on the archive.org queue. Its log ends // with `@@find-copy {host, dryRun, max, pages, posts, items, left, stopped?}`. export async function findPageCopiesAction(req: { article?: string; siteId?: string; channel?: string; max?: number; dryRun?: boolean; }): Promise { const paths = getPaths(); let host: ReportHost; try { if (req.article) { host = await articlesWorkHost(paths, [req.article], { only: true }); } else if (req.siteId) { if (!isValidSiteId(req.siteId)) return { ok: false, error: `"${req.siteId}" is not a valid site id` }; if (!listSiteIds(paths).includes(req.siteId)) return { ok: false, error: `No site "${req.siteId}"` }; host = siteReportHost(paths, getSite(req.siteId, paths)); } else { host = await articlesWorkHost(paths); } } catch (e) { return { ok: false, error: (e as Error).message }; } if (req.channel) { const config = await readChannelConfig(paths, req.channel); if (!config) return { ok: false, error: `No such channel: ${req.channel}` }; if (!isWaybackPagesChannel(config)) return { ok: false, error: `${req.channel} is not a Wayback pages channel` }; } return runManagedFunction({ kind: "find-copy", queueKey: WAYBACK_PAGES_QUEUE, paths, ...(req.channel ? { channelSlug: req.channel } : {}), fn: async (onLog, signal) => { const r = await findPageCopies({ paths, host, ...(req.channel ? { channel: req.channel } : {}), ...(req.max !== undefined ? { max: req.max } : {}), dryRun: req.dryRun === true, signal, onLog, }); onLog(`${FIND_COPY_RESULT_MARKER}${JSON.stringify(r)}`); const touched = new Set(r.items.filter((i) => i.outcome === "imported" && i.channel).map((i) => `/channels/${i.channel}`)); if (touched.size > 0) safeRevalidate([...touched]); if (signal.aborted) throw new Error("cancelled"); }, }); }