import { NextResponse } from "next/server"; import { FIND_CLIPS_BODY_KEYS, enqueueFindClips } from "yt-dlp-transcript-common/controller/findClips"; import { findClipsDeps } from "../_findClips"; import { jobResponse, ops, reqSlug, reqVideoId } from "../_lib"; export const dynamic = "force-dynamic"; // POST { slug, id, target?, segment?, project?, whilePaused?, dryRun? } // dryRun -> { ok: true, dryRun: true, plan: { steps: [{id, label, run, why}], umtoolUrl, workersPaused } } // else -> { ok: true, jobId } // // FIND CLIPS (release 36, lane A; controller/findClips.ts): the clip finder's // chain for ONE video as one job — persist the source video, the corpus // transcript, word timings (data//words.json), the chat replay (YouTube), // diarization — each step skipped when its output exists and named in the // log — then umtool's clips route (`mode: "new"`, `scope: "auto"`, or the // `segment` asked), followed to the end. The log ends `@@find-clips {json}`: // the project, its clip editor's URL, the segments umtool found and what each // step did; data//find-clips.json keeps it for the video page. // // `target` is the cut's length in seconds; `segment` a segment id umtool // found ("s2"); `project` names the umtool project a run makes (default from // the id); `whilePaused` runs the two transcriptions during a pause-all on a // worker the pause alone switched off. Refused before a job: an unknown // channel or video, UMTOOL_URL or WORKER_TOKEN unset on the editor. export async function POST(request: Request) { return ops(request, FIND_CLIPS_BODY_KEYS, async (body) => { const slug = reqSlug(body, "slug"); const id = reqVideoId(body, "id"); const out = await enqueueFindClips(body, findClipsDeps(slug, id)); if (out.dryRun) return NextResponse.json({ ok: true, dryRun: true, plan: out.plan }); return jobResponse(out.result); }); }