import { NextResponse } from "next/server"; import { savePageNowAction, savePageNowDryRunAction } from "../../../channels/[slug]/waybackLiveActions"; import { jobResponse, ops, optBool, optString, reqString } from "../_lib"; export const dynamic = "force-dynamic"; // POST { url, slug?, dryRun? } -> { ok: true, jobId } | (dryRun) { ok: true, dryRun: true, wouldAsk, … } // // SAVE PAGE NOW (release 37 S5, controller/savePageNow.ts): the Wayback // Machine asked to capture `url` now, with archive.org's S3 keys (the // editor's ARCHIVE_ORG_S3_ACCESS + ARCHIVE_ORG_S3_SECRET, else the mode-600 // file settings `archiveOrg.s3KeyFile` names) — a `save-page-now` job on the // archive.org queue that asks for the capture (the page alone), polls its // status, and, with `slug` (a Wayback pages channel), starts an import-page // job of the capture. The log ends with `@@save-page-now {ok, url, slug?, // spnJobId, captureTs, originalUrl, waybackUrl, importJobId?, importError?, // polls, error?}`. `dryRun` answers what it would ask and starts nothing. // Every refusal is the controller's sentence (no keys among them); the keys // are never echoed. export async function POST(request: Request) { return ops(request, ["url", "slug", "dryRun"], async (body) => { const url = reqString(body, "url"); const slug = optString(body, "slug")?.trim() || undefined; if (optBool(body, "dryRun") === true) { const r = await savePageNowDryRunAction(url, slug); if (!r.ok) return NextResponse.json({ ok: false, error: r.error }, { status: 400 }); return NextResponse.json(r); } return jobResponse(await savePageNowAction(url, slug, "ops")); }); }