// recordingClock-read — the time map's READ, in plain JS (lane one-clock). // // evidenceClip.mjs's saved-video tier reads `data//clock.json` under bare // node (umtool's report-to-video scripts), so the read cannot be the TS // sidecar's (recordingClock-server.ts declares the file and writes it). The // shape check is the same one, coerceRecordingClock; like every sidecar read, // anything wrong reads as null. import { readFile, stat } from "node:fs/promises"; import path from "node:path"; import { CLOCK_FILE, clockMatches, coerceRecordingClock } from "./recordingClock.mjs"; /** * A video dir's clock, or null (absent, unreadable, malformed). * @param {string} videoDir * @returns {Promise} */ export async function readRecordingClock(videoDir) { try { return coerceRecordingClock(JSON.parse(await readFile(path.join(/* turbopackIgnore: true */ videoDir, CLOCK_FILE), "utf8"))); } catch { return null; } } /** * The clock that applies to cutting `container` — the map about THIS container * (same size as when it was measured) — or null: none, or a stale one (the * video saved again: its map is another file's). * @param {string} videoDir * @param {string} container the saved container's path * @returns {Promise} */ export async function clockForContainer(videoDir, container) { const clock = await readRecordingClock(videoDir); if (!clock) return null; if (path.basename(container) !== clock.target.file) return null; try { const s = await stat(container); return clockMatches(clock, { targetBytes: s.size }) ? clock : null; } catch { return null; } }