import { NextResponse } from "next/server"; import { HOMEPAGE_TARGET } from "yt-dlp-transcript-common/publish/stamps"; import { enqueueAsks, lastJobOf, refusalsOf } from "../_publish"; import { ops, optBool, optPreviewBranch, opsFail, OpsInputError } from "../_lib"; export const dynamic = "force-dynamic"; // AN ALIAS (release 18): the homepage's build (forced), then with `deploy` its deploy. The body and the answer are the // route's old ones; the work is publish stages on the publish queue // (../_publish.ts), as `POST /api/ops/publish` {"verb": "homepage"} runs them. // // → { ok, jobId } — the run's last job (the deploy when there is one), as // before; `previewUrl` with a preview. export async function POST(request: Request) { return ops(request, ["deploy", "preview"], async (body) => { const deploy = optBool(body, "deploy") === true; const preview = optPreviewBranch(body); if (preview !== undefined && !deploy) { throw new OpsInputError('"preview" needs "deploy": true — a build alone deploys nothing'); } const run = await enqueueAsks([ { target: HOMEPAGE_TARGET, build: { force: true }, ...(deploy ? { deploy: { where: preview ? ("preview" as const) : ("production" as const), ...(preview ? { preview } : {}), force: true } } : {}), }, ]); const job = lastJobOf(run, HOMEPAGE_TARGET); if (!job) return opsFail(refusalsOf(run).map((r) => r.error).join("; ") || "nothing was enqueued"); return NextResponse.json({ ok: true, jobId: job.jobId, runId: run.runId, ...(job.previewUrl ? { previewUrl: job.previewUrl } : {}), }); }); } export function GET() { return NextResponse.json({ ok: false, error: "POST only" }, { status: 405 }); }