import { normalizeChannelAction } from "../../../channels/[slug]/normalizeActions"; import { OpsInputError, jobResponse, ops, optBool, optString, reqSlug, reqVideoId, type OpsBody } from "../_lib"; export const dynamic = "force-dynamic"; // POST { slug, ids?: string[], force?, queueKey? } -> { ok: true, jobId } // // Write each video's transcript.cues.json from its raw transcript (the // caption-track rule for VTTs), as the digest card's Normalize button does // (normalizeActions.ts, controller/normalizeAll.ts) — the file every reader // without an index build wants. `ids` narrows it to those videos, every one // held by the channel; `force` rewrites a cues.json that is already fresh. On // the channel's own queue. function optIds(body: OpsBody): string[] | undefined { const v = body.ids; if (v === undefined) return undefined; if (!Array.isArray(v) || v.length === 0) { throw new OpsInputError('"ids" must be a non-empty array of video ids'); } return [...new Set(v.map((id, i) => reqVideoId({ [`ids[${i}]`]: id }, `ids[${i}]`)))]; } export async function POST(request: Request) { return ops(request, ["slug", "ids", "force", "queueKey"], async (body) => jobResponse( await normalizeChannelAction(reqSlug(body, "slug"), optString(body, "queueKey"), { ids: optIds(body), force: optBool(body, "force") ?? false, }), ), ); }