import { reportsExportAction } from "../../../sites/lib/reportsExportAction"; import { jobResponse, OpsInputError, ops, optString, optSubset, reqString } from "../_lib"; import { isValidSiteId } from "yt-dlp-transcript-common/lib/site"; import { REPORT_EXPORT_FORMATS } from "yt-dlp-transcript-common/lib/report/views"; export const dynamic = "force-dynamic"; // POST { siteId: string, reportId?: string, formats?: ("html"|"pdf"|"md"|"zip")[] } // -> { ok: true, jobId } // // An adapter: one call to the action the site's Reports tab posts. Writes each // published report (or the one named) as report.html, report.pdf, report.md // and an evidence pack (or the formats named) into the site's report-exports // staging, as one `reports-export` job on prepare's queue. The job fails, // naming each, when an export cannot be written. export async function POST(request: Request) { return ops(request, ["siteId", "reportId", "formats"], async (body) => { const siteId = reqString(body, "siteId"); if (!isValidSiteId(siteId)) { throw new OpsInputError( `"${siteId}" is not a valid site id (lowercase letters, digits and "-"; must start with a letter or digit)`, ); } const reportId = optString(body, "reportId"); const formats = optSubset(body, "formats", REPORT_EXPORT_FORMATS, "the export formats"); return jobResponse( await reportsExportAction(siteId, { ...(reportId !== undefined ? { reportId } : {}), ...(formats ? { formats } : {}), }), ); }); }