import { NextResponse } from "next/server"; import { getPaths } from "yt-dlp-transcript-common/lib/paths"; import { FRAME_SCAN_BODY_KEYS, enqueueFrameScan } from "yt-dlp-transcript-common/controller/frameScan"; import { jobResponse, ops } from "../_lib"; export const dynamic = "force-dynamic"; // POST { slug, id, profile?, everySeconds?, from?, to?, maxFrames?, model?, // maxUsd?, hero?, framesPerAsk?, crop?, fresh?, evict?, rederive? } // -> { ok: true, jobId, model, queueKey } (evict: { ok: true, evicted }) // // The frame scan (release 30, lane P), as a `frame-scan` job: the video's // saved container sampled every `everySeconds` (default // settings.generation.frames.everySeconds) into a frame cache on the channel's // media side, near-duplicate frames skipped, the rest read by a vision model // through the profile (poker), and `frame-scan..json` written beside // the video: readings, the numbers the streamer said, the derived series, // events and segments. On `frames` (API) or `draft:local` (a local vision // model). The same body again resumes: read frames are not asked again. // Refused when the video is not saved (the sentence names the persist-videos // body), past the day's API cap, or with a maxUsd over caps.max. `evict: true` // removes the frame cache and answers at once; `rederive: true` works the // sidecar's `derived` out again from its stored readings (no model, no frame) // and answers `{ rederived: {before, after, tournaments, eventsByKind} }`. The // log ends `@@frame-scan {json}`. // // AN ADAPTER: the refusals are the controller's (controller/frameScan.ts). export async function POST(request: Request) { return ops(request, FRAME_SCAN_BODY_KEYS, async (body) => { const out = await enqueueFrameScan(body, { paths: getPaths() }); if ("evicted" in out) return NextResponse.json({ ok: true, evicted: out.evicted }); if ("rederived" in out) return NextResponse.json({ ok: true, rederived: out.rederived }); if (!out.result.ok || !("model" in out)) return jobResponse(out.result); void out.result.stream.cancel(); return NextResponse.json({ ok: true, jobId: out.result.jobId, model: out.model, queueKey: out.queueKey }); }); }