commit a517df7b8d2a97a1803b5d17df067c17df41d70d
parent fc98e21530d3f597db391341fe036c050ec3bf30
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Sat, 14 Nov 2026 03:26:21 -0500
Merge lane/clip-kit-2 (follow-up): a presented take plays its own built clip, and a public page is refused a clip that no longer hides what the cut asks for
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
6 files changed, 100 insertions(+), 21 deletions(-)
diff --git a/umtool/app/api/report/segment/route.ts b/umtool/app/api/report/segment/route.ts
@@ -1,4 +1,4 @@
-import { rangeResponse, resolveClip, segmentFor } from "@/lib/report/serve.mjs";
+import { rangeResponse, resolveClip, segmentFor, segmentHidesAsAsked } from "@/lib/report/serve.mjs";
export const dynamic = "force-dynamic";
@@ -22,20 +22,31 @@ export const dynamic = "force-dynamic";
// in a stream it did not fully download. rangeResponse() is the one
// implementation, shared with /api/report/video.
+//
+// `take=<id>`: that take's own segment (takes/<id>/out/…), the clip checked against the take's cut -- resolved from
+// the take id and the clip id alone. `public=1` (a public Present's built segment, present.mjs censoredSegmentsOf):
+// served only when the segment's cut record hides exactly the regions the clip asks for now (clip-censor.mjs), so
+// a page can never be pointed at a stale, unhidden file.
+
export async function GET(request: Request) {
const url = new URL(request.url);
+ const take = url.searchParams.get("take") || null;
const r = await resolveClip(
url.searchParams.get("project") ?? "",
url.searchParams.get("clip") ?? "",
+ { take },
);
if ("error" in r) return new Response(r.error, { status: r.status });
- const seg = await segmentFor(r.project, r.clip.id);
+ const seg = await segmentFor(r.project, r.clip.id, { take });
if (!seg) {
// A missing segment is the NORMAL state of a clip nobody has rendered yet,
// not an error worth a stack trace. The bench says so in words.
return new Response("no segment has been built for this clip yet", { status: 404 });
}
+ if (url.searchParams.get("public") === "1" && !(await segmentHidesAsAsked(seg.abs, r.clip, r.manifest))) {
+ return new Response("this segment does not hide the regions this clip hides now: it is not served to a public page", { status: 409 });
+ }
const fresh = url.searchParams.get("v") === String(seg.mtimeMs);
const headers: Record<string, string> = {
diff --git a/umtool/components/projects/present/PresentView.tsx b/umtool/components/projects/present/PresentView.tsx
@@ -58,7 +58,7 @@ type ClipSlide = SlideBase & {
* A PUBLIC payload of a clip with hidden regions (no `media`: the raw window is never named): its built segment,
* which hides them in the file (`segment` its version), or null -- the slide says the clip is not shown.
*/
- censored?: { segment: number; seconds: number | null } | null;
+ censored?: { segment: number; seconds: number | null; take?: string } | null;
};
type TextSlide = SlideBase & { kind: "section" | "day" | "teaser" | "card"; lines?: string[]; tail?: string | null; seconds?: number | null; heading?: string; within?: string | null };
type VideoSlide = SlideBase & { kind: "video"; src: string; from: number; to: number; seconds: number };
@@ -495,7 +495,7 @@ function ClipView({ slide, project, take, playing, sound, censor, onDone }: { sl
const src = media
? `/api/report/raw?${new URLSearchParams({ project, clip: slide.entry ?? slide.id, ...(take ? { take } : {}), file: media.name, ...(media.v ? { v: media.v } : {}) }).toString()}`
: built
- ? `/api/report/segment?${new URLSearchParams({ project, clip: slide.entry ?? slide.id, v: String(built.segment) }).toString()}`
+ ? `/api/report/segment?${new URLSearchParams({ project, clip: slide.entry ?? slide.id, ...(built.take ? { take: built.take } : {}), public: "1", v: String(built.segment) }).toString()}`
: null;
// Where it is in its source, followed every frame; past a span's end, on to the next, past the last, done.
useEffect(() => {
diff --git a/umtool/docs/knobs.md b/umtool/docs/knobs.md
@@ -554,7 +554,7 @@ the SOURCE picture and may be limited to a span of the clip.
| the clip editor's player, the clip bench | outlined and filled, with **Peek** (off by default) to see under them there only |
| the claim bench, the candidates panel, a cited clip (the article player) | the RECORDING's boxes (`render.censor` matched on its video; a cited project clip's own too), outlined, Peek off |
| **public** | |
-| Present's public payload (`public=1`, `umtool present --public`) | a clip with boxes carries NO raw window (`media: null`): it plays its BUILT segment (`/api/report/segment`, when that segment's record hides exactly its boxes: `censored.segment`), else the slide says the clip is not shown (`censored: null`). A page outside umtool cannot reach `/api/report/*` at all, so a public export must carry the segment itself |
+| Present's public payload (`public=1`, `umtool present --public`) | a clip with boxes carries NO raw window (`media: null`): it plays its BUILT segment -- a presented take's own (`takes/<t>/out/…`), never the draft's under its name -- when that segment's record hides exactly its boxes (`censored.segment`, `censored.take`), else the slide says the clip is not shown (`censored: null`). `/api/report/segment?…&public=1` refuses (409) a segment whose record does not hide the clip's boxes now, so a page cannot be pointed at a stale file. A page outside umtool cannot reach `/api/report/*` at all, so a public export must carry the segment itself |
| **refused** | |
| a montage (`render.montage`) | REFUSED by name (a montage re-cuts its pictures and draws no boxes yet) |
| a basic cut (`render.mode: "basic"`) | REFUSED by name, `render.blur: "off"` or not |
diff --git a/umtool/lib/report/present.mjs b/umtool/lib/report/present.mjs
@@ -36,7 +36,7 @@ import { clockZoneOf } from "umtool-report-to-video/post-clock";
import { estimateSchedule } from "umtool-report-to-video/deck";
import { gapsOf, keptSpans } from "umtool-report-to-video/gaps";
import { clipBlurOf } from "umtool-report-to-video/clip-blur";
-import { censorRecordOf, censorRegionsOf } from "umtool-report-to-video/clip-censor";
+import { censorRegionsOf } from "umtool-report-to-video/clip-censor";
import { playViewWith } from "./playView.mjs";
import { projectRedaction } from "./postRedaction.mjs";
import { sectionModel } from "./sectionEdit.mjs";
@@ -321,7 +321,7 @@ function postSlideId(e) {
* read by presentPayload: `{v, seconds}` by entry id), else null -- the slide says the clip is not shown. The
* operator's payload keeps the window, the regions overlaid on the operator's screen.
*
- * @param {{ view: Record<string, any>, manifest: Record<string, any>, red: any, canUncensor?: boolean, censoredSegments?: Map<string, { v: number, seconds: number | null }> }} o
+ * @param {{ view: Record<string, any>, manifest: Record<string, any>, red: any, canUncensor?: boolean, censoredSegments?: Map<string, { v: number, seconds: number | null, take?: string | null }> }} o
*/
export function presentFrom({ view, manifest, red, canUncensor = true, censoredSegments = new Map() }) {
const render = manifest.render ?? {};
@@ -442,7 +442,7 @@ export function presentFrom({ view, manifest, red, canUncensor = true, censoredS
video: e.video,
channel: e.channel ?? null,
media: withheld ? null : (e.media ?? null),
- ...(withheld ? { censored: seg ? { segment: seg.v, seconds: seg.seconds } : null } : {}),
+ ...(withheld ? { censored: seg ? { segment: seg.v, seconds: seg.seconds, ...(seg.take ? { take: seg.take } : {}) } : null } : {}),
spans,
seconds: Math.round(spans.reduce((n, s) => n + (s.to - s.from), 0) * 1000) / 1000,
title: words?.title || text(e.heading),
@@ -528,7 +528,7 @@ export async function presentPayload(project, { take = null, bare = false, canUn
if ("error" in r) return r;
const { anonymiseManifest } = await import("umtool-report-to-video/post-anon");
const manifest = anonymity ? anonymiseManifest(r.manifest, anonymity.doc, { set: anonymity.set }) : r.manifest;
- return presentFrom({ view: r.view, manifest, red, canUncensor, censoredSegments: canUncensor ? new Map() : await censoredSegmentsOf(project, manifest) });
+ return presentFrom({ view: r.view, manifest, red, canUncensor, censoredSegments: canUncensor ? new Map() : await censoredSegmentsOf(project, manifest, { take: r.view?.take?.id ?? null }) });
}
/**
@@ -536,23 +536,25 @@ export async function presentPayload(project, { take = null, bare = false, canUn
* regions a clip asks for now, by entry id -- what a public Present plays instead of the raw window. A segment cut
* with other boxes (or none) is not used.
*
+ * A take's own segments when a take is presented (takes/<t>/out/…), never the draft's under its name.
+ *
* @param {{ id: string, dir: string }} project
- * @param {Record<string, any>} manifest
+ * @param {Record<string, any>} manifest the cut presented (the take's, when one is)
+ * @param {{ take?: string | null }} [opts]
*/
-export async function censoredSegmentsOf(project, manifest) {
- const { segmentFor } = await import("./serve.mjs");
+export async function censoredSegmentsOf(project, manifest, { take = null } = {}) {
+ const { segmentFor, segmentHidesAsAsked } = await import("./serve.mjs");
const { readFile } = await import("node:fs/promises");
const out = new Map();
for (const e of manifest.timeline ?? []) {
if (e?.type !== "clip") continue;
- const want = censorRecordOf(censorRegionsOf(e, manifest.render ?? {}, manifest.provenance ?? {}));
- if (!want.length) continue;
- const seg = await segmentFor(project, e.id).catch(() => null);
- if (!seg) continue;
+ if (!censorRegionsOf(e, manifest.render ?? {}, manifest.provenance ?? {}).length) continue;
+ const seg = await segmentFor(project, e.id, { take }).catch(() => null);
+ // The route's own rule (segmentHidesAsAsked): exactly the boxes asked for now.
+ if (!seg || !(await segmentHidesAsAsked(seg.abs, e, manifest))) continue;
const rec = await readFile(/* turbopackIgnore: true */ seg.abs.replace(/\.mp4$/, ".cut.json"), "utf8").then(JSON.parse, () => null);
- if (JSON.stringify(rec?.censor ?? []) !== JSON.stringify(want)) continue;
const seconds = typeof rec?.start === "number" && typeof rec?.end === "number" ? Math.round((rec.end - rec.start) * 1000) / 1000 : null;
- out.set(e.id, { v: seg.mtimeMs, seconds });
+ out.set(e.id, { v: seg.mtimeMs, seconds, take });
}
return out;
}
diff --git a/umtool/lib/report/present.test.mjs b/umtool/lib/report/present.test.mjs
@@ -297,3 +297,46 @@ test("a PUBLIC payload never names the raw window of a clip that hides regions:
assert.equal(built.censored.seconds, 2);
assert.equal(built.media, null);
});
+
+test("a public Present of a TAKE plays the take's own built segment, by the same exact-boxes rule -- never the draft's under its name", async () => {
+ const own = { style: "black", boxes: [[0.1, 0.1, 0.2, 0.2]] };
+ const p = await project("take-seg", [{ type: "clip", id: "c01", video: "v1", start: 1, end: 3, lock: true, censor: own }], {}, { takes: { t1: { title: "The take" } } });
+ await mkdir(path.join(p.dir, "out", "clips-raw"), { recursive: true });
+ await writeFile(path.join(p.dir, "out", "clips-raw", "v1_0.00-6.00.mp4"), "raw window");
+ const rec = (censor) => JSON.stringify({ version: 1, id: "c01", start: 1, end: 3, censor });
+ const HID = [{ box: [0.1, 0.1, 0.2, 0.2], style: "black" }];
+ // The draft's segment hides the boxes; the take's is a different file.
+ const draft = path.join(p.dir, "out", "sourced", "segments");
+ const takeSegs = path.join(p.dir, "takes", "t1", "out", "sourced", "segments");
+ await mkdir(draft, { recursive: true });
+ await mkdir(takeSegs, { recursive: true });
+ await writeFile(path.join(draft, "c01.mp4"), "the draft's");
+ await writeFile(path.join(draft, "c01.cut.json"), rec(HID));
+ const { utimes } = await import("node:fs/promises");
+ await utimes(path.join(draft, "c01.mp4"), new Date(1_000_000_000_000), new Date(1_000_000_000_000));
+ // The take's segment cut WITHOUT the boxes: not used, and the draft's is not used in its place.
+ await writeFile(path.join(takeSegs, "c01.mp4"), "the take's");
+ await writeFile(path.join(takeSegs, "c01.cut.json"), rec([]));
+ const slide = async () => (await presentPayload(p, { take: "t1", canUncensor: false })).slides.find((s) => s.entry === "c01");
+ assert.equal((await slide()).censored, null);
+ // The take's hiding them: it is the one named.
+ await writeFile(path.join(takeSegs, "c01.cut.json"), rec(HID));
+ await utimes(path.join(takeSegs, "c01.mp4"), new Date(1_500_000_000_000), new Date(1_500_000_000_000));
+ const c = (await slide()).censored;
+ assert.equal(c.take, "t1");
+ assert.equal(c.segment, 1_500_000_000_000);
+ // The draft presented: the draft's, with no take.
+ const d = (await presentPayload(p, { canUncensor: false })).slides.find((s) => s.entry === "c01").censored;
+ assert.deepEqual([d.segment, d.take], [1_000_000_000_000, undefined]);
+ // The lookup takes a take id, never a path; the route's rule is the same exact-boxes rule.
+ const { segmentFor, segmentHidesAsAsked } = await import("./serve.mjs");
+ assert.equal(await segmentFor(p, "c01", { take: "../t1" }), null);
+ assert.equal(await segmentFor(p, "c01", { take: "t1/../.." }), null);
+ const seg = await segmentFor(p, "c01", { take: "t1" });
+ assert.equal(seg.rel, "takes/t1/out/sourced/segments/c01.mp4");
+ const clip = { type: "clip", id: "c01", video: "v1", start: 1, end: 3, censor: own };
+ assert.equal(await segmentHidesAsAsked(seg.abs, clip, { render: {} }), true);
+ assert.equal(await segmentHidesAsAsked(seg.abs, { ...clip, censor: { boxes: [[0, 0, 0.5, 0.5]] } }, { render: {} }), false, "a box changed since: stale, refused");
+ await writeFile(path.join(takeSegs, "c01.cut.json"), rec([]));
+ assert.equal(await segmentHidesAsAsked(seg.abs, clip, { render: {} }), false, "a segment cut without them");
+});
diff --git a/umtool/lib/report/serve.mjs b/umtool/lib/report/serve.mjs
@@ -16,6 +16,7 @@ import { REPORTS_ROOT, inside, resolveInRoots } from "../paths.mjs";
import { walkProjects } from "../projects/walk.mjs";
import { DEFAULT_VARIANT, FFMPEG_BIN, VARIANTS, WIN_EPS, probeDims, probeMedia, variantPaths } from "umtool-report-to-video/build-video";
import { rawCacheOf } from "./raw-cache.mjs";
+import { isTakeId } from "./takes.mjs";
import {
channelsDirFor,
clipWindowDirs,
@@ -630,11 +631,18 @@ export function absOf(win) {
* Returns the mtime as well, because a re-render writes the SAME path: without
* it in the URL a browser would keep showing the segment it cached before the
* edit, which is the one thing a re-render button must never do.
+ *
+ * @param {{ dir: string }} project
+ * @param {string} clipId
+ * @param {{ take?: string | null }} [opts] a take's own segments (takes/<take>/out/…), by its id
*/
-export async function segmentFor(project, clipId) {
+export async function segmentFor(project, clipId, { take = null } = {}) {
+ // A TAKE's own segments (takes/<take>/out/…), by its id alone: a take id is a plain name, never a path.
+ if (take !== null && !isTakeId(take)) return null;
+ const base = take ? path.posix.join("takes", String(take)) : "";
for (const rel of [
- path.posix.join("out", DEFAULT_VARIANT, "segments"),
- path.posix.join("out", "segments"),
+ path.posix.join(base, "out", DEFAULT_VARIANT, "segments"),
+ path.posix.join(base, "out", "segments"),
]) {
const relFile = path.posix.join(rel, `${clipId}.mp4`);
const abs = resolveInRoots(path.join(project.dir, relFile));
@@ -646,6 +654,21 @@ export async function segmentFor(project, clipId) {
}
/**
+ * Does the segment at `abs` hide exactly the regions `clip` asks for in `manifest` now (its cut record's `censor`,
+ * clip-censor.mjs censorRecordOf)? A segment with no record hides none.
+ *
+ * @param {string} abs
+ * @param {Record<string, any>} clip
+ * @param {Record<string, any>} manifest
+ */
+export async function segmentHidesAsAsked(abs, clip, manifest) {
+ const { censorRecordOf, censorRegionsOf } = await import("umtool-report-to-video/clip-censor");
+ const want = censorRecordOf(censorRegionsOf(clip, manifest?.render ?? {}, manifest?.provenance ?? {}));
+ const rec = await readFile(/* turbopackIgnore: true */ abs.replace(/\.mp4$/, ".cut.json"), "utf8").then(JSON.parse, () => null);
+ return JSON.stringify(Array.isArray(rec?.censor) ? rec.censor : []) === JSON.stringify(want);
+}
+
+/**
* The same membership rule, for a LEDGER claim.
*
* A claim id is checked against the ledger of the project named in the request,