commit 81cff877b0bf4a9c4bc5ae8602589a543cbba3fe
parent e73f98b4ba95816e997dc1d0e9f2240ee2732ed6
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Mon, 9 Nov 2026 15:34:46 -0500
umtool: a quick clip's spec is ids -- never "..", never a leading "-"
quickClipSpec (the CLI and POST /api/report/quick-clip) refuses a channel or video that
is all dots or starts with "-", and an end not after the start.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
4 files changed, 28 insertions(+), 8 deletions(-)
diff --git a/umtool/app/api/report/quick-clip/route.ts b/umtool/app/api/report/quick-clip/route.ts
@@ -2,7 +2,7 @@ import path from "node:path";
import { getJob, jobView, runningJob, startJob } from "@/lib/jobs";
import { refuseCaller } from "@/lib/report/caller";
import { UMTOOL_DIR } from "@/lib/report/driver.mjs";
-import { parseClipSpec } from "@/lib/report/clipEditorModel.mjs";
+import { quickClipSpec } from "@/lib/report/quickClip.mjs";
export const dynamic = "force-dynamic";
@@ -26,9 +26,8 @@ export async function POST(request: Request) {
const body = (await request.json().catch(() => null)) as Record<string, unknown> | null;
if (!body || typeof body !== "object") return Response.json({ error: "expected JSON" }, { status: 400, headers });
const spec = String(body.spec ?? "").trim();
- const parsed = parseClipSpec(spec);
- if (!parsed || !(parsed.end > parsed.start)) {
- return Response.json({ error: "spec is <channel>/<video>@<start>-<end> in seconds, the end after the start" }, { status: 400, headers });
+ if (!quickClipSpec(spec)) {
+ return Response.json({ error: 'spec is <channel>/<video>@<start>-<end> in seconds, the end after the start, its ids neither "." nor starting "-"' }, { status: 400, headers });
}
const snap = body.snap === undefined || body.snap === null || body.snap === "" ? null : String(body.snap);
if (snap !== null && snap !== "words") return Response.json({ error: "snap is words, or nothing" }, { status: 400, headers });
diff --git a/umtool/e2e/basic-mode.spec.ts b/umtool/e2e/basic-mode.spec.ts
@@ -101,6 +101,9 @@ test("quick clip: POST /api/report/quick-clip ends done -- the window asked of t
await page.setViewportSize({ width: 1366, height: 768 });
expect((await page.request.post("/api/report/quick-clip", { data: { spec: "basicyt/quickvid" } })).status()).toBe(400);
expect((await page.request.post("/api/report/quick-clip", { data: { spec: "basicyt/quickvid@10-14", snap: "letters" } })).status()).toBe(400);
+ for (const spec of ["../quickvid@10-14", "..@1-2", "-rf/quickvid@10-14", "basicyt/..@10-14", "basicyt/-x@10-14"]) {
+ expect((await page.request.post("/api/report/quick-clip", { data: { spec } })).status(), spec).toBe(400);
+ }
const started = await page.request.post("/api/report/quick-clip", { data: { spec: "basicyt/quickvid@10-14", title: "E2E quick clip" } });
expect(started.status(), await started.text()).toBe(202);
diff --git a/umtool/lib/report/quickClip.mjs b/umtool/lib/report/quickClip.mjs
@@ -61,6 +61,19 @@ class CliError extends Error {}
const r2 = (x) => Math.round(Number(x) * 100) / 100;
const fin = (v) => typeof v === "number" && Number.isFinite(v);
+/**
+ * A quick clip's spec, parsed and checked: `<channel>/<video>@<start>-<end>`, the end after the start, and
+ * neither id a path trick -- not all dots (`..`) and not starting with `-` (an argv flag) -- so the names
+ * that reach the disk and a child's argv are ids. Null when it is not one. Pure.
+ * @param {unknown} spec
+ */
+export function quickClipSpec(spec) {
+ const c = parseClipSpec(spec);
+ if (!c || !(c.end > c.start)) return null;
+ for (const id of [c.channel, c.video]) if (/^\.+$/.test(id) || id.startsWith("-")) return null;
+ return c;
+}
+
/** A project slug from words: lower-case letters, digits and dashes, at most 48, never `share-…` (a deliverables link's name). */
export function quickClipSlug({ title = null, channel, video, start }) {
const clean = (words) => String(words).toLowerCase().normalize("NFKD").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 48).replace(/-+$/, "");
@@ -168,9 +181,8 @@ async function editorWords({ path: file, start, end, out }, { emit = () => {} }
* @returns {Promise<{ project: string, dir: string, output: string, snapped: null | { cutStart: number, cutEnd: number, first: string, last: string }, share: { platform: string | null, archive: string | null, text: string } }>}
*/
export async function quickClip(ask, { root = REPORTS_ROOT, channelsDir = CHANNELS_DIR, sitesDir = SITES_DIR, say = () => {}, cfg = null, pollMs = POLL_MS, progress = null, log = console.log, err = console.error, deps = {} } = {}) {
- const spec = parseClipSpec(ask.spec);
- if (!spec) throw new CliError(`"${ask.spec}" is not <channel>/<video>@<start>-<end> (seconds)`);
- if (!(spec.end > spec.start)) throw new CliError(`${ask.spec}: the end must be after the start`);
+ const spec = quickClipSpec(ask.spec);
+ if (!spec) throw new CliError(`"${ask.spec}" is not <channel>/<video>@<start>-<end> (seconds, the end after the start; ids, not "." or "-…")`);
if (ask.snap && ask.snap !== "words") throw new CliError(`--snap ${ask.snap}: words is the one snap`);
// The recording as the corpus keeps it (a Rumble embed id: its URL-slug folder), and the id the archive serves.
const video = await resolveVideoDirId(channelsDir, spec.channel, spec.video).catch(() => spec.video);
diff --git a/umtool/lib/report/quickClip.test.mjs b/umtool/lib/report/quickClip.test.mjs
@@ -21,7 +21,7 @@ process.env.CHANNELS_DIR = CORPUS;
process.env.SITES_DIR = SITES;
process.env.CHANNELS_FALLBACK = "0";
-const { quickClip, quickClipCommand, quickClipSlug, siteOriginFor, snapToWords } = await import("./quickClip.mjs");
+const { quickClip, quickClipCommand, quickClipSlug, quickClipSpec, siteOriginFor, snapToWords } = await import("./quickClip.mjs");
const { shareCommand } = await import("./shareLineCli.mjs");
test.after(() => rm(ROOT, { recursive: true, force: true }));
@@ -58,6 +58,12 @@ test("snapToWords: the first word mostly after the start, the last mostly before
assert.equal(snapToWords([{ w: "x", start: 30, end: 31 }], 1, 2), null, "no word inside");
});
+test("quickClipSpec: a spec of ids -- never `..`, never a leading `-`, the end after the start", () => {
+ assert.deepEqual(quickClipSpec("yt/vid1@40-60.5"), { channel: "yt", video: "vid1", start: 40, end: 60.5 });
+ for (const bad of ["../vid@1-2", "../..@1-2", "./x@1-2", "-rf/x@1-2", "yt/..@1-2", "yt/-x@1-2", "yt/v@5-2", "yt/v@5-5", "yt/v", "yt/v@a-b"]) assert.equal(quickClipSpec(bad), null, bad);
+ assert.deepEqual(quickClipSpec("a.b/v.1@1-2"), { channel: "a.b", video: "v.1", start: 1, end: 2 }, "a dot inside an id is fine");
+});
+
test("siteOriginFor: the first public site that carries the channel", async () => {
assert.equal(await siteOriginFor("yt"), "https://a-site.example");
assert.equal(await siteOriginFor("nobody"), null);