// THE CUES AROUND A CITED SECOND (release 32 R2): what umtool's "Add a claim" // lists to pick a quote from — the record's cues as compose reads them // (readCitedRecord: the normalized cues, else whisper, else the English VTTs, // en-orig first). Here, in publish/, because the reader is; the claim's writer // (controller/handEdits.ts) may not import this layer. // // SERVER-ONLY. import { getPaths, type Paths } from "../lib/paths"; import { readCitedRecord } from "./composeReports"; export type CueLine = { start: number; end: number; text: string }; /** The record's cues from `from` to `to` seconds (its best track: the one compose reads), and its title. */ export async function cuesAround( channel: string, id: string, from: number, to: number, paths: Pick = getPaths(), ): Promise<{ title: string | null; cues: CueLine[] } | null> { if (!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(channel) || !id || /[/\\]|^\.\.?$/.test(id)) return null; const rec = await readCitedRecord(paths.channelsDir, channel, id).catch(() => null); if (!rec) return null; return { title: rec.summary.title ?? null, cues: rec.cues.filter((c) => c.end > from && c.start < to).map((c) => ({ start: c.start, end: c.end, text: c.text })), }; }