import { NextResponse } from "next/server"; import { importPageAction, importPageDryRunAction } from "../../../channels/[slug]/waybackPagesActions"; import { jobResponse, ops, optBool, optString, reqSlug, reqString } from "../_lib"; export const dynamic = "force-dynamic"; // POST { slug, url, at?, dryRun? } -> { ok: true, jobId } | (dryRun) { ok: true, dryRun: true, wouldFetch, … } // // ONE Wayback Machine capture of a page that is not a video into `slug`, a // Wayback pages channel (platform "webpage"; release 37 S1): `url` a capture's // replay URL (https://web.archive.org/web/[mod]/), or the page's own // URL with `at` (YYYYMMDD[hhmmss]) for the capture nearest it. An // `import-page` job on the archive.org queue: the raw body stored under the // channel's `pages/`, its page records written to the channel's posts; the // log ends with `@@import-page {ok, captureTs, originalUrl, records, written, // updated, unchanged, already?, error?}`. `dryRun` answers what it would fetch // and starts nothing. // // Every refusal is the controller's sentence: no such channel, not a Wayback // pages channel, a URL that names no capture, a video ("use import-video"), // an X capture outside an X channel while X is private. // // Release 37 lane F: `url` may be an archive.today copy (https://archive.ph/, // //, /newest/), or the page's own URL with `at` and // `source: "archive.today"` for its copy nearest that date — an import-page // job on the `platform:archive.today` queue, at archive.today's pace. A // refusal at the source is in the log's result as `refusal` ("excluded", // "challenge", "rate-limited", …). export async function POST(request: Request) { return ops(request, ["slug", "url", "at", "source", "dryRun"], async (body) => { const slug = reqSlug(body, "slug"); const url = reqString(body, "url"); const at = optString(body, "at")?.trim() || undefined; const source = optString(body, "source")?.trim() || undefined; if (optBool(body, "dryRun") === true) { const r = await importPageDryRunAction(slug, url, at, source); if (!r.ok) return NextResponse.json({ ok: false, error: r.error }, { status: 400 }); return NextResponse.json(r); } return jobResponse(await importPageAction(slug, url, at, "ops", source)); }); }