import { MAX_SPAN, windowOf } from "@/lib/research/corpus"; import { SourceError } from "@/lib/research/sources"; import { fail, ok } from "../_respond"; export const dynamic = "force-dynamic"; // GET ?source=&channel=&video=&t=[&span=30][&track=][&kind=post] // -> WindowResponse (lib/research/types.ts) // // The transcript ±span seconds around a cue (max 600), the cue nearest `t` // lit, its citation in the house format, and what umtool can play from this // machine. `kind=post` reads a post instead (no timeline). export async function GET(request: Request) { try { const q = new URL(request.url).searchParams; const channel = q.get("channel")?.trim() ?? ""; const video = q.get("video")?.trim() ?? ""; if (!channel || !video) throw new SourceError("channel and video are required"); const t = Number(q.get("t") ?? "0"); const span = Number(q.get("span") ?? "30"); if (!Number.isFinite(t) || t < 0) throw new SourceError("t is a second, 0 or more"); if (!Number.isFinite(span) || span <= 0 || span > MAX_SPAN) throw new SourceError(`span is 1 to ${MAX_SPAN} seconds`); return ok( await windowOf({ source: q.get("source") ?? "", channel, video, t, span, ...(q.get("track") ? { track: q.get("track")! } : {}), kind: q.get("kind") === "post" ? "post" : "video", }), ); } catch (e) { return fail(e); } }