// The narration review's view of a project (release 25, T5): every narrated // card of the manifest (every cut's), its words, engine and voice, what the // card shows on screen, its review state (report-to-video's // narration-review.mjs), and whether its voice is already kept beside the // build (`out/narration/`, from a play or a build). What the page draws and // what the route answers after each action -- one shape. Since release 28 the // verdicts are the drafts review's (drafts.review.json, narration's rows // `narrate//narration`; release 25's narration.review.json still read). // // Plain ESM: `node --test` runs it with no TypeScript. import path from "node:path"; import { stat } from "node:fs/promises"; import { estimatedNarratedCardSeconds, narrationWords } from "umtool-report-to-video/narration"; import { DRAFTS_REVIEW_FILE, readNarrationReview, reviewRows } from "umtool-report-to-video/narration-review"; import { narrationDir, narrationWavPath, readNarrationRecord } from "umtool-report-to-video/narration-store"; import { allCardReadings, readingOfRecord } from "./cardNarrationCli.mjs"; /** * @param {string} projectDir * @param {any} manifest the whole manifest, as written */ export async function narrationReviewView(projectDir, manifest) { const review = await readNarrationReview(projectDir); const dir = narrationDir(path.join(projectDir, "out")); const timeline = Array.isArray(manifest?.timeline) ? manifest.timeline : []; const rows = []; // Every card's readings, the store read once for the view (review 1, a nit). const kept = await allCardReadings(projectDir); for (const r of reviewRows(manifest, review)) { const at = timeline.findIndex((e) => e?.id === r.id); const e = timeline[at] ?? {}; const rec = await readNarrationRecord(dir, r.key); const wav = rec ? await stat(narrationWavPath(dir, r.key)).catch(() => null) : null; rows.push({ id: r.id, at, text: r.text, engine: r.engine, voice: r.voice, speed: r.speed, words: narrationWords(r.text), estimate: estimatedNarratedCardSeconds(e, manifest.render), seconds: e.seconds ?? null, screen: { kicker: e.kicker ?? null, heading: e.heading ?? null, sub: e.sub ?? null, title: e.onscreen?.title ?? null, style: e.style ?? null, }, // Who drafted these words (release 28; null: written by hand). drafted: e.drafted?.narration && typeof e.drafted.narration === "object" ? e.drafted.narration : null, state: r.state, verdict: r.row?.verdict ?? null, note: r.row?.note ?? "", judgedText: r.row?.text ?? "", judgedAt: r.row?.at ?? "", kept: rec ? { seconds: rec.seconds, disclosure: rec.disclosure, mtimeMs: wav ? Math.round(wav.mtimeMs) : 0 } : null, // Its reading and tuning now, and every reading kept for it (lane line-rerun: Read again, Pick). key: r.key, reading: Number.isInteger(e.narration?.reading) ? e.narration.reading : 0, tuning: e.narration?.tuning ?? null, madeWith: rec?.tuning ?? null, readings: (kept.get(r.id) ?? []).map((x) => ({ key: x.key, text: x.text, reading: readingOfRecord(x), tuning: x.askedTuning ?? null, seconds: x.seconds, createdAt: x.createdAt ?? null })), }); } const counts = { approved: 0, rejected: 0, edited: 0, unreviewed: 0 }; for (const r of rows) counts[r.state] += 1; return { file: DRAFTS_REVIEW_FILE, exists: review.exists, error: review.error ?? null, rows, counts }; }