// THE OPERATOR'S CAPTION-TRACK PICK. The editor's "Set as transcript" copies // the chosen track to transcript.en.vtt and writes this sidecar beside it; // while it is present, the caption-track rule ranks transcript.en.vtt first // (lib/videoStatus.ts, englishVttsByPreference) — above en-orig, which the rule // otherwise prefers. Only the file's PRESENCE is read by the rule; the record // says which track was copied and when, for a person reading the dir. // // SERVER-ONLY (node:fs). import { TRANSCRIPT_PIN_FILENAME } from "./videoStatus"; import { sidecar, sidecarField } from "./sidecar-server"; export type TranscriptPinRecord = { // The track the operator picked (copied to transcript.en.vtt). from: string; pinnedAt: string; }; // Any parseable record still pins: the rule reads presence, so the record's // shape must never make a pin read as absent here and present there. export function coerceTranscriptPin(value: unknown): TranscriptPinRecord { const v = value as Partial | null; return { from: typeof v?.from === "string" ? v.from : "", pinnedAt: typeof v?.pinnedAt === "string" ? v.pinnedAt : "", }; } export const transcriptPinSidecar = sidecar( TRANSCRIPT_PIN_FILENAME, sidecarField(coerceTranscriptPin), ); export async function pinTranscript(videoDir: string, from: string): Promise { await transcriptPinSidecar.write(videoDir, { from, pinnedAt: new Date().toISOString(), }); }