rushes 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/AGENTS.md +36 -8
- package/README.md +75 -4
- package/dist/cli/doctor.js +35 -10
- package/dist/cli/main.js +200 -18
- package/dist/core/batches.js +35 -3
- package/dist/core/exportNotes.js +9 -5
- package/dist/core/formats.js +159 -0
- package/dist/core/found.js +333 -0
- package/dist/core/labels.js +192 -0
- package/dist/core/log.js +190 -0
- package/dist/core/logEvents.js +193 -0
- package/dist/core/logText.js +122 -0
- package/dist/core/media.js +119 -13
- package/dist/core/notes.js +35 -4
- package/dist/core/project.js +69 -1
- package/dist/core/schema.js +147 -1
- package/dist/core/store.js +19 -3
- package/dist/mcp/client.js +13 -1
- package/dist/mcp/tools.js +181 -11
- package/dist/server/app.js +495 -38
- package/dist/server/assets.js +19 -7
- package/dist/server/files.js +61 -4
- package/dist/server/found.js +1216 -0
- package/dist/server/logbook.js +208 -0
- package/dist/server/loudness.js +7 -3
- package/dist/server/peaks.js +3 -2
- package/dist/server/proxy.js +16 -4
- package/dist/server/start.js +15 -2
- package/package.json +1 -1
- package/skills/rushes/SKILL.md +9 -4
- package/web-dist/assets/index-BDMm5p1-.css +1 -0
- package/web-dist/assets/index-C9dBtlRy.js +3 -0
- package/web-dist/index.html +2 -2
- package/web-dist/assets/index-ChXjhVC5.js +0 -3
- package/web-dist/assets/index-Cj_tr1I-.css +0 -1
package/dist/server/app.js
CHANGED
|
@@ -2,14 +2,15 @@ import { Hono } from "hono";
|
|
|
2
2
|
import { streamSSE } from "hono/streaming";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { RushesError, InvalidError, NotFoundError } from "../core/errors.js";
|
|
5
|
-
import { addFile, addVariant, addVersion, ensureProjectIdOnce, lockPicture, resolveVideo, setShots, shotAt } from "../core/project.js";
|
|
5
|
+
import { addFile, addFormat, addVariant, addVersion, ensureProjectIdOnce, lockPicture, resolveCut, resolveVideo, setShots, shotAt } from "../core/project.js";
|
|
6
6
|
import { addTake, editSection, setSections } from "../core/script.js";
|
|
7
|
-
import { addNote, applyReply, applyUserEdit, filterNotes } from "../core/notes.js";
|
|
7
|
+
import { addNote, applyReply, applyUserEdit, checkNoteFormat, filterNotes } from "../core/notes.js";
|
|
8
|
+
import { FORMAT_ID_RE, MAX_FORMATS, isPictureSize, versionFormats } from "../core/formats.js";
|
|
8
9
|
import { createBatch, latestBatch } from "../core/batches.js";
|
|
9
10
|
import { exportFileName, notesMarkdown } from "../core/exportNotes.js";
|
|
10
11
|
import { tabStates } from "../core/tabs.js";
|
|
11
12
|
import { fromManifestPath, toManifestPath } from "../core/paths.js";
|
|
12
|
-
import { probe } from "../core/media.js";
|
|
13
|
+
import { AUDIO_FORMATS, PROBE_TIMEOUT_MS, VIDEO_EXT, giveUpAfter, probe, probeVideo, videoGaveUp } from "../core/media.js";
|
|
13
14
|
import { PROXY_PATH, ProxyJobs } from "./proxy.js";
|
|
14
15
|
import { PeakJobs } from "./peaks.js";
|
|
15
16
|
import { lstat, mkdir, readFile, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
@@ -17,12 +18,17 @@ import { randomUUID } from "node:crypto";
|
|
|
17
18
|
import { existsSync } from "node:fs";
|
|
18
19
|
import { basename, extname, join } from "node:path";
|
|
19
20
|
import { fileURLToPath } from "node:url";
|
|
20
|
-
import { GRAB_PATH, SCREENSHOT_PATH, contentDisposition, contentType, inside, isInlineSafeType, mediaSecurityHeaders, registeredMedia, sendFile, servableFile } from "./files.js";
|
|
21
|
+
import { GRAB_PATH, OUTSIDE_CUT_EXT, OUTSIDE_MEDIA_EXT, SCREENSHOT_PATH, contentDisposition, contentType, cutOnlyFiles, foundMediaFile, inside, isInlineSafeType, mediaSecurityHeaders, registeredMedia, sendFile, servableFile } from "./files.js";
|
|
22
|
+
import { BRING_IN_MAX, FoundScanner, ffprobeDuration, foundAnnouncer } from "./found.js";
|
|
21
23
|
import { candidatePaths, listAssets, fpsFor, screenshotName } from "./assets.js";
|
|
22
24
|
import { osRevealer, osOpener, OPEN_SAFE_EXT } from "./reveal.js";
|
|
23
25
|
import { LaneStageSchema, SectionStatusSchema, StageSchema, BoxSchema, FileKindSchema, MarkSchema, ProjectIdSchema, ShotSchema, LEVEL_MIN, LEVEL_MAX, LEVEL_STEP } from "../core/schema.js";
|
|
26
|
+
import { LABEL_MAX, oneLineOf } from "../core/labels.js";
|
|
27
|
+
import { byOf, logBookFor } from "./logbook.js";
|
|
28
|
+
import { broughtInEvent, cutEvent, fileEvent, formatEvent, lineEvent, lockEvent, notesSentEvent, picksEvent, repliesEvent, scriptEvent, takeEvent, variantEvent, } from "../core/logEvents.js";
|
|
29
|
+
import { LOG_AREAS, LOG_MAX, changeLogFileName, logText, recentChanges } from "../core/logText.js";
|
|
24
30
|
import { defaultRunner, measureMix } from "./loudness.js";
|
|
25
|
-
export const VERSION = "0.
|
|
31
|
+
export const VERSION = "0.3.0";
|
|
26
32
|
async function body(c, schema) {
|
|
27
33
|
let json;
|
|
28
34
|
try {
|
|
@@ -37,6 +43,10 @@ async function body(c, schema) {
|
|
|
37
43
|
return parsed.data;
|
|
38
44
|
}
|
|
39
45
|
const t = z.number().nonnegative();
|
|
46
|
+
// §21.3: a format id, "9x16" or "2.39x1". Capped like the schema's own id.
|
|
47
|
+
const formatId = z.string().max(16).regex(FORMAT_ID_RE);
|
|
48
|
+
/** The longest path a format may be registered under (FoundItem and FoundPathsBody use the same). */
|
|
49
|
+
const MAX_PATH = 1024;
|
|
40
50
|
const NewNoteBody = z.object({
|
|
41
51
|
stage: StageSchema,
|
|
42
52
|
video: z.string().nullish(),
|
|
@@ -50,6 +60,7 @@ const NewNoteBody = z.object({
|
|
|
50
60
|
box: BoxSchema.nullish(),
|
|
51
61
|
grab: z.string().nullish(),
|
|
52
62
|
marks: z.array(MarkSchema).max(4).optional(),
|
|
63
|
+
format: formatId.nullish(),
|
|
53
64
|
});
|
|
54
65
|
const UserEditBody = z.object({
|
|
55
66
|
text: z.string().optional(),
|
|
@@ -60,6 +71,7 @@ const UserEditBody = z.object({
|
|
|
60
71
|
tOut: t.nullable().optional(),
|
|
61
72
|
marks: z.array(MarkSchema).max(4).optional(),
|
|
62
73
|
status: z.enum(["todo", "done"]).optional(),
|
|
74
|
+
format: formatId.nullable().optional(),
|
|
63
75
|
});
|
|
64
76
|
const RepliesBody = z.object({
|
|
65
77
|
replies: z
|
|
@@ -72,7 +84,27 @@ const RepliesBody = z.object({
|
|
|
72
84
|
}))
|
|
73
85
|
.min(1),
|
|
74
86
|
});
|
|
75
|
-
|
|
87
|
+
// §22.4: `label` is a short label for the version list (R2: the limit is enforced here, not in the file).
|
|
88
|
+
const VersionBody = z.object({
|
|
89
|
+
video: z.string().min(1),
|
|
90
|
+
file: z.string().min(1),
|
|
91
|
+
note: z.string().optional(),
|
|
92
|
+
// Cleaned to one line first, so padding and invisible characters don't count, then counted in characters.
|
|
93
|
+
label: z
|
|
94
|
+
.string()
|
|
95
|
+
.transform(oneLineOf)
|
|
96
|
+
.refine((s) => Array.from(s).length <= LABEL_MAX, `label is ${LABEL_MAX} characters at most: put the detail in note`)
|
|
97
|
+
.optional(),
|
|
98
|
+
// §21.4: the other shapes of this same cut, registered in the same call. `file` is the main one.
|
|
99
|
+
formats: z.array(z.object({ file: z.string().min(1).max(MAX_PATH) })).max(MAX_FORMATS - 1).optional(),
|
|
100
|
+
});
|
|
101
|
+
// §21.4: `label` here is only a hint for the ratio's name ("2.39:1"), not a version's short label.
|
|
102
|
+
const FormatBody = z.object({
|
|
103
|
+
video: z.string().min(1).max(200).optional(),
|
|
104
|
+
version: z.string().min(1).max(64).optional(),
|
|
105
|
+
file: z.string().min(1).max(MAX_PATH),
|
|
106
|
+
label: z.string().trim().min(1).max(16).optional(),
|
|
107
|
+
});
|
|
76
108
|
const VariantBody = z.object({
|
|
77
109
|
stage: LaneStageSchema,
|
|
78
110
|
lane: z.string().optional(),
|
|
@@ -106,6 +138,9 @@ const NoteQuery = z.object({
|
|
|
106
138
|
status: z.enum(["todo", "done"]).optional(),
|
|
107
139
|
batch: z.string().optional(),
|
|
108
140
|
version: z.string().optional(),
|
|
141
|
+
// §21.4: a format's notes, with the all-format notes unless onlyThisFormat (R14: Picture only).
|
|
142
|
+
format: formatId.optional(),
|
|
143
|
+
onlyThisFormat: z.enum(["true", "false"]).optional(),
|
|
109
144
|
});
|
|
110
145
|
// ShotSchema's own limits (name trimmed 1-80 chars, tag at most 24) apply at the boundary; `n` is server-assigned.
|
|
111
146
|
const ShotsBody = z.object({
|
|
@@ -116,7 +151,11 @@ const LockBody = z.object({ version: z.string().nullable() });
|
|
|
116
151
|
const MixLoudnessBody = z.object({ lanes: z.array(LaneStageSchema).min(1) });
|
|
117
152
|
const SettingsBody = z.object({ autoProxy: z.boolean() }).strict();
|
|
118
153
|
// A time in seconds, 0 to 24 h: an empty value, NaN, Infinity or anything huge is a 400.
|
|
119
|
-
const FrameQuery = z.object({
|
|
154
|
+
const FrameQuery = z.object({
|
|
155
|
+
t: z.string().min(1).pipe(z.coerce.number().finite().min(0).max(86400)),
|
|
156
|
+
// R12: the format whose own file the frame is read from. The cut's primary when left out.
|
|
157
|
+
format: formatId.optional(),
|
|
158
|
+
});
|
|
120
159
|
const GrabBody = z.object({
|
|
121
160
|
video: z.string().regex(/^[a-z0-9][a-z0-9-]*$/),
|
|
122
161
|
version: z.string().regex(/^v\d+$/),
|
|
@@ -124,6 +163,8 @@ const GrabBody = z.object({
|
|
|
124
163
|
frame: z.number().int().nonnegative().max(10_000_000),
|
|
125
164
|
/** PNG bytes, base64, with or without a data: prefix. */
|
|
126
165
|
png: z.string().min(1),
|
|
166
|
+
// §21.5: the format on screen when it isn't the cut's primary. Must be one of the cut's shapes.
|
|
167
|
+
format: formatId.optional(),
|
|
127
168
|
});
|
|
128
169
|
const RevealBody = z.union([z.object({ path: z.string().min(1) }), z.object({ project: z.literal(true) })]);
|
|
129
170
|
const OpenBody = z.object({ path: z.string().min(1) });
|
|
@@ -134,12 +175,55 @@ const AddFileBody = z.object({
|
|
|
134
175
|
note: z.string().max(500).optional(),
|
|
135
176
|
video: z.string().optional(),
|
|
136
177
|
});
|
|
178
|
+
// §20.6: the found routes. A scan may name the film whose newest cut anchors the scoring.
|
|
179
|
+
const FoundItem = z.object({
|
|
180
|
+
path: z.string().min(1).max(1024),
|
|
181
|
+
kind: z.enum(["voice", "music", "sfx", "cut", "doc"]).optional(),
|
|
182
|
+
round: z.string().trim().min(1).max(64).optional(),
|
|
183
|
+
});
|
|
184
|
+
// §20.7: `wait` makes the scan answer once it and the adoption are done, with what's in and what's
|
|
185
|
+
// left. `include` (only with `wait`) brings in files the agent knows belong, before adopting.
|
|
186
|
+
const FoundScanBody = z
|
|
187
|
+
.object({
|
|
188
|
+
film: z.string().min(1).max(200).optional(),
|
|
189
|
+
wait: z.boolean().optional(),
|
|
190
|
+
include: z.array(FoundItem).max(BRING_IN_MAX).optional(),
|
|
191
|
+
})
|
|
192
|
+
.refine((b) => b.include === undefined || b.wait === true, { message: "include needs wait: true", path: ["include"] });
|
|
193
|
+
const FoundPathsBody = z.object({ paths: z.array(z.string().min(1).max(1024)).min(1).max(500) });
|
|
194
|
+
const FoundBringInBody = z.object({
|
|
195
|
+
files: z.array(FoundItem).min(1).max(BRING_IN_MAX),
|
|
196
|
+
film: z.string().min(1).max(200).optional(),
|
|
197
|
+
});
|
|
198
|
+
// §22.7: the Change Log's routes. A line is made one line and cut to 160 characters by the server (R21).
|
|
199
|
+
// Ruling a: a query it can't use is a 400 that says what to send, never a quiet default.
|
|
200
|
+
const LIMIT_WORDS = `limit must be a whole number from 1 to ${LOG_MAX}`;
|
|
201
|
+
/** 2026-10-07, optionally with a time (minutes, seconds, fractions) and a zone (Z or ±hh[:]mm). */
|
|
202
|
+
const ISO_DATE = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d{1,9})?)?(Z|[+-]\d{2}:?\d{2})?)?$/;
|
|
203
|
+
const LogQuery = z.object({
|
|
204
|
+
limit: z.string({ error: LIMIT_WORDS }).regex(/^\d+$/, LIMIT_WORDS).pipe(z.coerce.number().int(LIMIT_WORDS).min(1, LIMIT_WORDS).max(LOG_MAX, LIMIT_WORDS)).optional(),
|
|
205
|
+
area: z.enum(LOG_AREAS, { error: `area must be one of ${LOG_AREAS.join(", ")}` }).optional(),
|
|
206
|
+
// ISO style only: Date.parse alone would read "0" or "1" as a year (M4).
|
|
207
|
+
since: z
|
|
208
|
+
.string()
|
|
209
|
+
.refine((s) => ISO_DATE.test(s) && Number.isFinite(Date.parse(s)), "since must be a date and time, e.g. 2026-10-07T09:00:00Z")
|
|
210
|
+
.optional(),
|
|
211
|
+
});
|
|
212
|
+
const LogLineBody = z.object({
|
|
213
|
+
text: z.string().max(2000),
|
|
214
|
+
area: z.enum(LOG_AREAS, { error: `area must be one of ${LOG_AREAS.join(", ")}` }).optional(),
|
|
215
|
+
video: z.string().min(1).max(200).nullish(),
|
|
216
|
+
version: z.string().min(1).max(64).nullish(),
|
|
217
|
+
ref: z.string().min(1).max(300).nullish(),
|
|
218
|
+
});
|
|
137
219
|
// Big enough for a full-quality frame of a 4K original from the frame endpoint (§19.5), which
|
|
138
220
|
// Picture posts here as the grab: 3840×2160 RGB is 24.9 MB before PNG compression.
|
|
139
221
|
const MAX_GRAB_BYTES = 64 * 1024 * 1024;
|
|
140
222
|
const PNG_MAGIC = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
|
141
223
|
/** Where the built dashboard lives: <package>/web-dist, next to dist/ and src/. */
|
|
142
224
|
export const DEFAULT_WEB_DIR = fileURLToPath(new URL("../../web-dist/", import.meta.url));
|
|
225
|
+
/** How long a waiting scan (§20.7) answers at most, before it says it is still scanning. */
|
|
226
|
+
export const FOUND_WAIT_MS = 20_000;
|
|
143
227
|
const LOCAL_HOSTS = new Set(["127.0.0.1", "localhost"]);
|
|
144
228
|
/** Hostname of "host[:port]" or a full origin URL, lowercased, or null when it doesn't parse. */
|
|
145
229
|
function hostnameOf(value, isUrl) {
|
|
@@ -157,6 +241,58 @@ export function createApp(store, opts = {}) {
|
|
|
157
241
|
const open = opts.open ?? osOpener;
|
|
158
242
|
const jobs = opts.proxyJobs ?? new ProxyJobs(store);
|
|
159
243
|
const peaks = opts.peakJobs ?? new PeakJobs(store, { run: jobs.run, available: () => jobs.available() });
|
|
244
|
+
const found = opts.found ?? new FoundScanner({ store, probe: ffprobeDuration, announce: foundAnnouncer(store) });
|
|
245
|
+
// §22: the Change Log, shared with the found scanner (logBookFor keeps one per store).
|
|
246
|
+
const log = logBookFor(store);
|
|
247
|
+
const by = (c) => byOf(c.req.header("x-rushes-project"));
|
|
248
|
+
/** R17: writes exports/change-log-YYYY-MM-DD.md (a same-day export replaces it) and returns its path. Written as Export notes writes. */
|
|
249
|
+
async function exportChangeLog(now) {
|
|
250
|
+
const [project, script] = await Promise.all([store.read("project"), store.read("script")]);
|
|
251
|
+
const md = await log.markdown({ project, script }, now);
|
|
252
|
+
const name = changeLogFileName(now);
|
|
253
|
+
const dir = join(store.root, "exports");
|
|
254
|
+
await mkdir(dir, { recursive: true });
|
|
255
|
+
const tmp = join(dir, `.${name}.${process.pid}.${randomUUID()}.tmp`);
|
|
256
|
+
await writeFile(tmp, md, "utf8");
|
|
257
|
+
await rename(tmp, join(dir, name));
|
|
258
|
+
return `exports/${name}`;
|
|
259
|
+
}
|
|
260
|
+
const prober = opts.formatProbe ?? ((abs, signal) => probeVideo(abs, { signal }));
|
|
261
|
+
const proberTimeout = opts.formatProbeTimeoutMs ?? PROBE_TIMEOUT_MS;
|
|
262
|
+
/**
|
|
263
|
+
* Every read of a render (review I2): given up on like any ffprobe, so a stalled drive never holds
|
|
264
|
+
* a request, and stopped when the server closes or `stop` aborts.
|
|
265
|
+
*/
|
|
266
|
+
const readVideo = (abs, stop) => jobs.tracked((closing) => {
|
|
267
|
+
const signal = stop ? AbortSignal.any([closing, stop]) : closing;
|
|
268
|
+
if (signal.aborted)
|
|
269
|
+
return Promise.resolve(videoGaveUp("aborted"));
|
|
270
|
+
return giveUpAfter(prober(abs, signal), { timeout: proberTimeout, signal, gaveUp: videoGaveUp });
|
|
271
|
+
});
|
|
272
|
+
const isPlainFile = (abs) => stat(abs).then((s) => s.isFile(), () => false);
|
|
273
|
+
/**
|
|
274
|
+
* §21.3/§21.6: a render's shape on screen, length and rate, or the refusal in the user's words.
|
|
275
|
+
* Only a plain file on disk reaches the probe, and a format must have a video extension; the
|
|
276
|
+
* cut's own file (`primary`) is judged as it is without formats, by what ffprobe makes of it.
|
|
277
|
+
* The size comes back untouched: addFormat judges it (a size that isn't a picture is its RushesError).
|
|
278
|
+
*/
|
|
279
|
+
async function readRender(given, how = {}) {
|
|
280
|
+
const file = toManifestPath(store.root, given);
|
|
281
|
+
const abs = fromManifestPath(store.root, file);
|
|
282
|
+
if (!how.primary && !VIDEO_EXT.has(extname(file).toLowerCase().replace(/^\./, "")))
|
|
283
|
+
throw new RushesError(`${file} isn't a video file.`, 400, "not_video", { path: file });
|
|
284
|
+
if (!(await isPlainFile(abs)))
|
|
285
|
+
throw new RushesError(`File not found: ${file}`, 404, "missing_file", { path: file });
|
|
286
|
+
const r = await readVideo(abs, how.stop);
|
|
287
|
+
if (!r.ok) {
|
|
288
|
+
if (r.code === "no_ffprobe")
|
|
289
|
+
throw new RushesError("Registering a format needs ffprobe to read the ratio. Run `rushes doctor` for how to add it.", 501, "no_ffprobe");
|
|
290
|
+
if (r.code === "not_video")
|
|
291
|
+
throw new RushesError(`${file} isn't a video: ${r.reason}.`, 400, "not_video", { path: file });
|
|
292
|
+
throw new RushesError(`ffprobe couldn't read ${file}: ${r.reason}`, 422, "unreadable", { path: file });
|
|
293
|
+
}
|
|
294
|
+
return { file, width: r.width, height: r.height, duration: r.duration, fps: r.fps };
|
|
295
|
+
}
|
|
160
296
|
const app = new Hono();
|
|
161
297
|
// Every SSE client adds a change listener, so lift Node's default limit of ten.
|
|
162
298
|
store.setMaxListeners(0);
|
|
@@ -265,10 +401,33 @@ export function createApp(store, opts = {}) {
|
|
|
265
401
|
// falls through to candidatePaths, which does the readdir-backed discovery (§16.2's
|
|
266
402
|
// auto-discovered docs/captions/exports) that a registered path never needs.
|
|
267
403
|
const known = registeredMedia(project, script).has(path) || GRAB_PATH.test(path) || SCREENSHOT_PATH.test(path);
|
|
404
|
+
// The file on disk to send. For a found file it's exactly the path that was checked.
|
|
405
|
+
let file = fromManifestPath(store.root, path);
|
|
406
|
+
let viaFound = false;
|
|
268
407
|
if (!known) {
|
|
269
|
-
|
|
270
|
-
|
|
408
|
+
if (found.has(path)) {
|
|
409
|
+
// §20.5: a found file can be auditioned before it's brought in -- only one the last scan
|
|
410
|
+
// recorded (and not dismissed), only as a plain file inside the project folder, never
|
|
411
|
+
// through a symlink. Served with the same headers as everything else below.
|
|
412
|
+
const checked = await foundMediaFile(store.root, path);
|
|
413
|
+
if (!checked)
|
|
414
|
+
throw new NotFoundError("media", path);
|
|
415
|
+
file = checked;
|
|
416
|
+
viaFound = true; // already refused any symlink outright
|
|
417
|
+
}
|
|
418
|
+
else {
|
|
419
|
+
const candidates = await candidatePaths(store, project, script);
|
|
420
|
+
if (!candidates.has(path))
|
|
421
|
+
throw new NotFoundError("media", path);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
if (!viaFound) {
|
|
425
|
+
// §15.5: a registered file reached through a symlink out of the project is served only if it is media.
|
|
426
|
+
// Final review M2: a cut or format that resolves outside the project is served only as video or audio.
|
|
427
|
+
const servable = await servableFile(store.root, file, cutOnlyFiles(project, script).has(path) ? OUTSIDE_CUT_EXT : OUTSIDE_MEDIA_EXT);
|
|
428
|
+
if (!servable)
|
|
271
429
|
throw new NotFoundError("media", path);
|
|
430
|
+
file = servable;
|
|
272
431
|
}
|
|
273
432
|
// C1: a type a browser could render as a document (HTML, XML, SVG -- an SVG can carry
|
|
274
433
|
// script -- or anything this server doesn't otherwise recognise) is never served inline,
|
|
@@ -282,10 +441,6 @@ export function createApp(store, opts = {}) {
|
|
|
282
441
|
if (!info || !info.isFile() || info.isSymbolicLink())
|
|
283
442
|
throw new NotFoundError("media", path);
|
|
284
443
|
}
|
|
285
|
-
// §15.5: a registered file reached through a symlink out of the project is served only if it is media.
|
|
286
|
-
const file = await servableFile(store.root, fromManifestPath(store.root, path));
|
|
287
|
-
if (!file)
|
|
288
|
-
throw new NotFoundError("media", path);
|
|
289
444
|
const type = contentType(path);
|
|
290
445
|
const inlineSafe = isInlineSafeType(type);
|
|
291
446
|
const res = await sendFile(file, c.req.header("range"), inlineSafe ? type : "application/octet-stream");
|
|
@@ -306,7 +461,16 @@ export function createApp(store, opts = {}) {
|
|
|
306
461
|
throw new InvalidError("Frame grab must be a PNG");
|
|
307
462
|
const project = await store.read("project");
|
|
308
463
|
const fps = fpsFor(project, b.video, b.version);
|
|
309
|
-
|
|
464
|
+
// §21.5: a grab of a format is named with its ratio; the format must be one of this cut's. The
|
|
465
|
+
// dashboard names only a non-primary format (Task 2 review M4: an older cut with formats but no
|
|
466
|
+
// stored size has no primary id), so a grab with none is the primary's, which carries its own
|
|
467
|
+
// ratio whenever the cut has other formats and the primary's shape is known.
|
|
468
|
+
const version = project.videos.find((v) => v.id === b.video)?.versions.find((v) => v.id === b.version);
|
|
469
|
+
const shapes = version ? versionFormats(version) : [];
|
|
470
|
+
if (b.format !== undefined && !shapes.some((f) => f.id === b.format))
|
|
471
|
+
throw new NotFoundError("format", b.format);
|
|
472
|
+
const primary = version && version.formats.length > 0 ? shapes.find((f) => f.primary)?.id ?? null : null;
|
|
473
|
+
const name = screenshotName(b.video, b.version, b.frame, fps, b.format ?? primary);
|
|
310
474
|
const grab = `screenshots/${name}`;
|
|
311
475
|
await mkdir(join(store.root, "screenshots"), { recursive: true });
|
|
312
476
|
// Written to a temp name in the same directory, then renamed into place. Writing the
|
|
@@ -394,6 +558,7 @@ export function createApp(store, opts = {}) {
|
|
|
394
558
|
const b = await body(c, AddFileBody);
|
|
395
559
|
const file = toManifestPath(store.root, b.file);
|
|
396
560
|
const { result } = await store.update("project", (p) => addFile(p, { ...b, file }));
|
|
561
|
+
await log.add(() => fileEvent(result), by(c));
|
|
397
562
|
return c.json(result, 201);
|
|
398
563
|
});
|
|
399
564
|
app.post("/api/exports/notes", async (c) => {
|
|
@@ -413,8 +578,16 @@ export function createApp(store, opts = {}) {
|
|
|
413
578
|
const tmp = join(dir, `.${name}.${process.pid}.${randomUUID()}.tmp`);
|
|
414
579
|
await writeFile(tmp, md, "utf8");
|
|
415
580
|
await rename(tmp, join(dir, name));
|
|
416
|
-
|
|
581
|
+
// §22.7: Export notes also writes the change log, newest first, one heading per day. The notes
|
|
582
|
+
// are written by now, so a change log that can't be is left out (null), never a failed export.
|
|
583
|
+
const changeLog = await exportChangeLog(now).catch((e) => {
|
|
584
|
+
console.error(`Rushes: couldn't export the Change Log: ${e.message}`);
|
|
585
|
+
return null;
|
|
586
|
+
});
|
|
587
|
+
return c.json({ path: `exports/${name}`, changeLog }, 201);
|
|
417
588
|
});
|
|
589
|
+
// §22.8: the drawer's Export as Markdown.
|
|
590
|
+
app.post("/api/exports/change-log", async (c) => c.json({ path: await exportChangeLog(new Date()) }, 201));
|
|
418
591
|
app.post("/api/shutdown", (c) => {
|
|
419
592
|
if (opts.onShutdown)
|
|
420
593
|
setImmediate(opts.onShutdown);
|
|
@@ -425,12 +598,15 @@ export function createApp(store, opts = {}) {
|
|
|
425
598
|
let streams = 0;
|
|
426
599
|
app.get("/api/health", async (c) => {
|
|
427
600
|
const [project, id] = await Promise.all([store.read("project"), getProjectId()]);
|
|
428
|
-
|
|
601
|
+
// Ruling e: Change Log lines that couldn't be written are counted for `rushes doctor`, only when there are any.
|
|
602
|
+
const health = { ok: true, app: "rushes", version: VERSION, root: store.root, id, name: project.name, ...(log.failures ? { logFailures: log.failures } : {}) };
|
|
429
603
|
return c.json(c.req.query("test") === "1" ? { ...health, sse: streams } : health);
|
|
430
604
|
});
|
|
431
605
|
app.get("/api/state", async (c) => {
|
|
432
|
-
|
|
433
|
-
|
|
606
|
+
// §20.6: found is what the last scan left in memory; it never waits on a scan or a probe.
|
|
607
|
+
// §22.8: the log's head is read-only, so a state request never writes (R6).
|
|
608
|
+
const [project, script, notes, picks, batches, ffmpeg, foundSummary, logHead] = await Promise.all([
|
|
609
|
+
store.read("project"), store.read("script"), store.read("notes"), store.read("picks"), store.read("batches"), jobs.available(), found.summary(), log.head(),
|
|
434
610
|
]);
|
|
435
611
|
const tabs = tabStates(project, script, notes);
|
|
436
612
|
// §19.5: why each cut may play badly (or null). Never waits on a probe: an unprobed cut is
|
|
@@ -439,7 +615,90 @@ export function createApp(store, opts = {}) {
|
|
|
439
615
|
...v,
|
|
440
616
|
versions: await Promise.all(v.versions.map(async (ver) => ({ ...ver, proxyNeed: await jobs.needNow(fromManifestPath(store.root, ver.file)) }))),
|
|
441
617
|
})));
|
|
442
|
-
return c.json({ project: { ...project, videos }, script, notes, picks, batches, tabs, proxies: { ffmpeg, jobs: jobs.list() } });
|
|
618
|
+
return c.json({ project: { ...project, videos }, script, notes, picks, batches, tabs, proxies: { ffmpeg, jobs: jobs.list() }, found: foundSummary, log: logHead });
|
|
619
|
+
});
|
|
620
|
+
// ---- found: the project's other files (§20) ----
|
|
621
|
+
app.get("/api/found", async (c) => {
|
|
622
|
+
// `abs` stays on the server: the list speaks in manifest paths, as /media and the actions do.
|
|
623
|
+
const files = (await found.list()).map(({ abs: _abs, ...rest }) => rest);
|
|
624
|
+
// The hidden ones ride along, so Assets › Found can list them and restore any.
|
|
625
|
+
const hidden = (await found.hidden()).map(({ abs: _abs, ...rest }) => rest);
|
|
626
|
+
return c.json({ files, hidden });
|
|
627
|
+
});
|
|
628
|
+
app.post("/api/found/scan", async (c) => {
|
|
629
|
+
const b = await body(c, FoundScanBody);
|
|
630
|
+
if (b.wait) {
|
|
631
|
+
// §20.7. What the agent included wins over the scoring: its kinds are settled for the cut
|
|
632
|
+
// first (kept in found.json, ahead of any adoption), then the first pass, then the included
|
|
633
|
+
// files, then the current set. `added` is everything brought in this session, so a start-up
|
|
634
|
+
// adoption racing this request is never missed. Waiting stops at the cap: the rest carries
|
|
635
|
+
// on in the background and the answer says `scanning`.
|
|
636
|
+
const failed = [];
|
|
637
|
+
const alreadyIn = [];
|
|
638
|
+
const work = (async () => {
|
|
639
|
+
const settling = b.include?.length ? found.settleKinds(b.include, b.film) : Promise.resolve([]);
|
|
640
|
+
const [, kinds] = await Promise.all([found.scan({ film: b.film }), settling]);
|
|
641
|
+
let skipKinds = kinds;
|
|
642
|
+
if (b.include?.length) {
|
|
643
|
+
const included = await found.bringIn(b.include, { film: b.film, origin: "include" });
|
|
644
|
+
if (included.added.length)
|
|
645
|
+
await log.add(() => broughtInEvent(included.added, null), by(c));
|
|
646
|
+
// An included cut becomes the cut the scoring is matched to, and a project with no cut
|
|
647
|
+
// had nothing to record against: settle again now that the cut exists.
|
|
648
|
+
if (included.added.some((a) => a.kind === "cut"))
|
|
649
|
+
skipKinds = await found.settleKinds(b.include, b.film);
|
|
650
|
+
for (const f of included.failed) {
|
|
651
|
+
if (f.code === "already")
|
|
652
|
+
alreadyIn.push(f.path);
|
|
653
|
+
else
|
|
654
|
+
failed.push(f);
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
// The kinds are also passed on, so this adoption holds back whatever happens to the record.
|
|
658
|
+
failed.push(...(await found.adoptCurrentSet({ film: b.film, skipKinds })).failed);
|
|
659
|
+
})();
|
|
660
|
+
work.catch(() => undefined); // after the cap, a failure has nobody to tell
|
|
661
|
+
let timer;
|
|
662
|
+
const capped = await Promise.race([
|
|
663
|
+
work.then(() => false),
|
|
664
|
+
new Promise((r) => {
|
|
665
|
+
timer = setTimeout(() => r(true), opts.foundWaitMs ?? FOUND_WAIT_MS);
|
|
666
|
+
timer.unref?.();
|
|
667
|
+
}),
|
|
668
|
+
]).finally(() => clearTimeout(timer));
|
|
669
|
+
return c.json({
|
|
670
|
+
ok: true,
|
|
671
|
+
added: found.broughtInDetail(),
|
|
672
|
+
alreadyIn,
|
|
673
|
+
failed,
|
|
674
|
+
found: (await found.summary()).counts,
|
|
675
|
+
...(capped ? { scanning: true } : {}),
|
|
676
|
+
});
|
|
677
|
+
}
|
|
678
|
+
// Answers at once; the scan runs in the background and announces a change when it lands.
|
|
679
|
+
// Then §20.4's current set is adopted (a no-op without a cut, or when it's already in).
|
|
680
|
+
void found
|
|
681
|
+
.scan({ film: b.film })
|
|
682
|
+
.then(() => found.adoptCurrentSet({ film: b.film }))
|
|
683
|
+
.catch(() => undefined);
|
|
684
|
+
return c.json({ ok: true });
|
|
685
|
+
});
|
|
686
|
+
app.post("/api/found/bring-in", async (c) => {
|
|
687
|
+
const b = await body(c, FoundBringInBody);
|
|
688
|
+
const r = await found.bringIn(b.files, { film: b.film });
|
|
689
|
+
if (r.added.length)
|
|
690
|
+
await log.add(() => broughtInEvent(r.added, null), by(c));
|
|
691
|
+
return c.json(r);
|
|
692
|
+
});
|
|
693
|
+
app.post("/api/found/dismiss", async (c) => {
|
|
694
|
+
const b = await body(c, FoundPathsBody);
|
|
695
|
+
await found.dismiss(b.paths);
|
|
696
|
+
return c.json({ ok: true });
|
|
697
|
+
});
|
|
698
|
+
app.post("/api/found/restore", async (c) => {
|
|
699
|
+
const b = await body(c, FoundPathsBody);
|
|
700
|
+
await found.restore(b.paths);
|
|
701
|
+
return c.json({ ok: true });
|
|
443
702
|
});
|
|
444
703
|
app.get("/api/tabs", async (c) => {
|
|
445
704
|
const [project, script, notes] = await Promise.all([store.read("project"), store.read("script"), store.read("notes")]);
|
|
@@ -451,48 +710,120 @@ export function createApp(store, opts = {}) {
|
|
|
451
710
|
if (!q.success)
|
|
452
711
|
throw new InvalidError("Query is invalid", q.error.issues);
|
|
453
712
|
const { notes } = await store.read("notes");
|
|
454
|
-
return c.json({ notes: filterNotes(notes, q.data) });
|
|
713
|
+
return c.json({ notes: filterNotes(notes, { ...q.data, onlyThisFormat: q.data.onlyThisFormat === "true" }) });
|
|
455
714
|
});
|
|
456
715
|
app.post("/api/notes", async (c) => {
|
|
457
716
|
const b = await body(c, NewNoteBody);
|
|
458
717
|
// The client never sends shot; the server stamps it from the version's shots.
|
|
459
718
|
let shot = null;
|
|
460
|
-
if (b.stage === "picture"
|
|
719
|
+
if (b.stage === "picture" || b.format != null) {
|
|
461
720
|
const project = await store.read("project");
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
721
|
+
// §21.3: a format must be one of this cut's, and on a cut with formats a box belongs to one.
|
|
722
|
+
checkNoteFormat({ next: { stage: b.stage, video: b.video ?? null, version: b.version ?? null, format: b.format ?? null, box: b.box ?? null } }, project);
|
|
723
|
+
if (b.stage === "picture" && b.video && b.version && b.t != null) {
|
|
724
|
+
const version = project.videos.find((v) => v.id === b.video)?.versions.find((v) => v.id === b.version);
|
|
725
|
+
if (version)
|
|
726
|
+
shot = shotAt(version.shots, b.t);
|
|
727
|
+
}
|
|
465
728
|
}
|
|
466
729
|
const { result } = await store.update("notes", (f) => addNote(f, { ...b, shot, by: "user" }));
|
|
467
730
|
return c.json({ note: result }, 201);
|
|
468
731
|
});
|
|
469
732
|
app.patch("/api/notes/:id", async (c) => {
|
|
470
733
|
const b = await body(c, UserEditBody);
|
|
471
|
-
|
|
734
|
+
// §21.3 and R7: a change of format or box is checked against the note's cut as it is now.
|
|
735
|
+
const project = b.format !== undefined || b.box !== undefined ? await store.read("project") : null;
|
|
736
|
+
const check = project ? (next, prev) => checkNoteFormat({ next, prev, boxRedrawn: b.box !== undefined }, project) : undefined;
|
|
737
|
+
const { result } = await store.update("notes", (f) => applyUserEdit(f, { id: c.req.param("id"), ...b }, check));
|
|
472
738
|
return c.json({ note: result });
|
|
473
739
|
});
|
|
474
740
|
app.post("/api/replies", async (c) => {
|
|
475
741
|
const b = await body(c, RepliesBody);
|
|
476
742
|
const { result } = await store.update("notes", (f) => b.replies.map((r) => applyReply(f, r)));
|
|
743
|
+
await log.add(() => repliesEvent(result), by(c));
|
|
477
744
|
return c.json({ notes: result });
|
|
478
745
|
});
|
|
479
746
|
// ---- media ----
|
|
480
747
|
app.post("/api/versions", async (c) => {
|
|
481
748
|
const b = await body(c, VersionBody);
|
|
482
|
-
|
|
749
|
+
// §21.4 (R11): with formats, every file is read first and one refusal refuses the whole call.
|
|
750
|
+
// The refusal names the first refused file in the order given, never whichever read happened to
|
|
751
|
+
// finish first, so a call always gives the same message (CI run 37724786490). So a refusal stops
|
|
752
|
+
// only the reads after it (review M6): they can't change the answer. The ones before it run on,
|
|
753
|
+
// each bounded by its own give-up, since one of them may be the file to name.
|
|
754
|
+
let shapes = null;
|
|
755
|
+
if (b.formats?.length) {
|
|
756
|
+
const files = [b.file, ...b.formats.map((f) => f.file)];
|
|
757
|
+
const stops = files.map(() => new AbortController());
|
|
758
|
+
const settled = await Promise.allSettled(files.map((f, i) => readRender(f, { primary: i === 0, stop: stops[i].signal }).catch((e) => {
|
|
759
|
+
for (const later of stops.slice(i + 1))
|
|
760
|
+
later.abort();
|
|
761
|
+
throw e;
|
|
762
|
+
})));
|
|
763
|
+
// The first rejection in order is always a refusal of its own: only an earlier one stops a read.
|
|
764
|
+
const refused = settled.find((s) => s.status === "rejected");
|
|
765
|
+
if (refused)
|
|
766
|
+
throw refused.reason;
|
|
767
|
+
shapes = settled.map((s) => s.value);
|
|
768
|
+
const own = shapes[0];
|
|
769
|
+
if (!isPictureSize(own.width, own.height)) {
|
|
770
|
+
throw new RushesError(`${own.file} measures ${own.width}×${own.height}, which isn't a picture size, so Rushes can't tell its formats' shapes from it.`, 422, "no_primary_size", { path: own.file });
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
const file = shapes ? shapes[0].file : toManifestPath(store.root, b.file);
|
|
483
774
|
const abs = fromManifestPath(store.root, file);
|
|
484
|
-
// The proxy jobs' probe is ffprobe (tests inject a fake), so the cut's need is read from the same
|
|
485
|
-
|
|
775
|
+
// The proxy jobs' probe is ffprobe (tests inject a fake), so the cut's need is read from the same
|
|
776
|
+
// answer. §21.3 (R2): the primary's shape on screen is stored too, when it is a file that can be read.
|
|
777
|
+
const readOwn = async () => {
|
|
778
|
+
if (!(await isPlainFile(abs)))
|
|
779
|
+
return null;
|
|
780
|
+
const r = await readVideo(abs);
|
|
781
|
+
// Final review I1: a file ffprobe reads as another kind of container (a playlist or a GIF
|
|
782
|
+
// named .mp4) is not a cut. Anything else it can't read comes in with no size, as before.
|
|
783
|
+
if (!r.ok && r.container)
|
|
784
|
+
throw new RushesError(`${file} isn't a video: ${r.reason}.`, 400, "not_video", { path: file });
|
|
785
|
+
return r.ok ? r : null;
|
|
786
|
+
};
|
|
787
|
+
const [read, info] = await Promise.all([shapes ? Promise.resolve(shapes[0]) : readOwn(), jobs.probe(abs)]);
|
|
788
|
+
// Only a real picture size is stored; a plain cut without one goes in with no size, as cuts did
|
|
789
|
+
// before formats (a formats call was refused above).
|
|
790
|
+
const size = read && isPictureSize(read.width, read.height) ? read : null;
|
|
791
|
+
const formatWarnings = [];
|
|
486
792
|
let lockedVersion = null;
|
|
487
793
|
let autoProxy = false;
|
|
794
|
+
let films = 1;
|
|
488
795
|
const { result } = await store.update("project", (p) => {
|
|
489
|
-
const out = addVersion(p, {
|
|
796
|
+
const out = addVersion(p, {
|
|
797
|
+
video: b.video, file, note: b.note, label: b.label, duration: info.duration ?? read?.duration ?? null, fps: info.fps ?? read?.fps ?? null,
|
|
798
|
+
width: size?.width ?? null, height: size?.height ?? null,
|
|
799
|
+
});
|
|
800
|
+
// Throwing here leaves project.json unwritten: the cut and its formats land together or not at all.
|
|
801
|
+
for (const s of shapes?.slice(1) ?? []) {
|
|
802
|
+
let added;
|
|
803
|
+
try {
|
|
804
|
+
added = addFormat(p, { video: out.video.id, version: out.version.id, ...s });
|
|
805
|
+
}
|
|
806
|
+
catch (e) {
|
|
807
|
+
// Final review M7: the version is new, so the shape it "already has" came from this same
|
|
808
|
+
// call. Name the two files; the version is never created, so never name it.
|
|
809
|
+
if (e instanceof RushesError && e.code === "same_ratio") {
|
|
810
|
+
throw new RushesError(`${s.file} has the same shape as ${e.detail.file} (${e.detail.label}). Register one render of each shape.`, 409, "same_ratio", { path: s.file, with: e.detail.file });
|
|
811
|
+
}
|
|
812
|
+
throw e;
|
|
813
|
+
}
|
|
814
|
+
if (added.warning)
|
|
815
|
+
formatWarnings.push(added.warning);
|
|
816
|
+
}
|
|
490
817
|
lockedVersion = out.video.lockedVersion;
|
|
491
818
|
autoProxy = p.autoProxy;
|
|
819
|
+
films = p.videos.length;
|
|
492
820
|
if (info.fps && p.videos.length === 1 && p.videos[0].versions.length === 1)
|
|
493
821
|
p.fps = info.fps;
|
|
494
822
|
return out;
|
|
495
823
|
});
|
|
824
|
+
// One write, one line (R4): a cut that comes with its other shapes says so on its own line
|
|
825
|
+
// ("v2 and its 9:16 added: …"), rather than a line per shape.
|
|
826
|
+
await log.add(() => cutEvent(films, result.video, result.version, result.version.formats.map((f) => f.label)), by(c));
|
|
496
827
|
// §19.5: say when the cut is likely to play badly, and start its proxy straight away when the
|
|
497
828
|
// project asks for that. Without ffmpeg, nothing is offered (needFor is null).
|
|
498
829
|
// §19.9: its waveform is made in the background; nothing here waits for it.
|
|
@@ -505,9 +836,43 @@ export function createApp(store, opts = {}) {
|
|
|
505
836
|
if (autoProxy && !jobs.isClosing)
|
|
506
837
|
proxy.proxyJob = jobs.start(result.video.id, result.version.id);
|
|
507
838
|
}
|
|
839
|
+
const warnings = formatWarnings.length ? { formatWarnings } : {};
|
|
508
840
|
if (lockedVersion)
|
|
509
|
-
return c.json({ ...result, ...proxy, warning: `Picture is locked at ${lockedVersion}` }, 201);
|
|
510
|
-
return c.json({ ...result, ...proxy }, 201);
|
|
841
|
+
return c.json({ ...result, ...proxy, ...warnings, warning: `Picture is locked at ${lockedVersion}` }, 201);
|
|
842
|
+
return c.json({ ...result, ...proxy, ...warnings }, 201);
|
|
843
|
+
});
|
|
844
|
+
// ---- formats (§21.4) ----
|
|
845
|
+
app.post("/api/formats", async (c) => {
|
|
846
|
+
const b = await body(c, FormatBody);
|
|
847
|
+
const render = await readRender(b.file);
|
|
848
|
+
// The cut it joins, pinned now, and its own shape when it has none yet (a cut from before formats).
|
|
849
|
+
const cut = resolveCut(await store.read("project"), b.video, b.version);
|
|
850
|
+
let primarySize = null;
|
|
851
|
+
if (cut.version.width === null || cut.version.height === null) {
|
|
852
|
+
const own = fromManifestPath(store.root, cut.version.file);
|
|
853
|
+
const r = (await isPlainFile(own)) ? await readVideo(own) : null;
|
|
854
|
+
if (r?.ok && !isPictureSize(r.width, r.height)) {
|
|
855
|
+
throw new RushesError(`${cut.version.file} measures ${r.width}×${r.height}, which isn't a picture size, so Rushes can't tell a new shape from it.`, 422, "no_primary_size", { version: cut.version.id });
|
|
856
|
+
}
|
|
857
|
+
if (r?.ok)
|
|
858
|
+
primarySize = { width: r.width, height: r.height };
|
|
859
|
+
}
|
|
860
|
+
// Inside the update, so two registrations of one shape at once can't both land: the second
|
|
861
|
+
// sees the first's format and gets §21.3's sentence.
|
|
862
|
+
let films = 1;
|
|
863
|
+
const { result } = await store.update("project", (p) => {
|
|
864
|
+
films = p.videos.length;
|
|
865
|
+
return addFormat(p, { ...render, video: cut.video.id, version: cut.version.id, label: b.label, primarySize });
|
|
866
|
+
});
|
|
867
|
+
// §22.5: "9:16 added to v2".
|
|
868
|
+
await log.add(() => formatEvent(films, result.video, result.version.id, result.format), by(c));
|
|
869
|
+
return c.json({
|
|
870
|
+
video: { id: result.video.id, name: result.video.name },
|
|
871
|
+
version: result.version,
|
|
872
|
+
format: result.format,
|
|
873
|
+
...(result.warning ? { warning: result.warning } : {}),
|
|
874
|
+
...(result.labelNote ? { labelNote: result.labelNote } : {}),
|
|
875
|
+
}, 201);
|
|
511
876
|
});
|
|
512
877
|
// ---- proxies (§19.5) ----
|
|
513
878
|
/** The cut a proxy or frame route names, or a 404. The video may be given by id, slug or name. */
|
|
@@ -576,15 +941,21 @@ export function createApp(store, opts = {}) {
|
|
|
576
941
|
throw new InvalidError("Query is invalid: t must be a time in seconds", q.error.issues);
|
|
577
942
|
await jobs.requireFfmpeg();
|
|
578
943
|
const { project, version } = await cutOf(c.req.param("video"), c.req.param("version"));
|
|
579
|
-
|
|
944
|
+
// R12: Grab Frame on a format reads that format's own file. Frames are counted at the cut's fps.
|
|
945
|
+
const view = q.data.format ? versionFormats(version).find((f) => f.id === q.data.format) : undefined;
|
|
946
|
+
if (q.data.format && !view)
|
|
947
|
+
throw new NotFoundError("format", q.data.format);
|
|
948
|
+
const source = view && !view.primary ? view.file : version.file;
|
|
949
|
+
const orig = fromManifestPath(store.root, source);
|
|
580
950
|
const exists = await stat(orig).then((s) => s.isFile(), () => false);
|
|
581
951
|
if (!exists)
|
|
582
|
-
throw new RushesError("The original file is missing", 404, "missing_file", { path:
|
|
952
|
+
throw new RushesError("The original file is missing", 404, "missing_file", { path: source });
|
|
583
953
|
const fps = version.fps ?? project.fps;
|
|
584
954
|
let frame = Math.round(q.data.t * fps);
|
|
585
955
|
// A time at or past the end lands on the last frame rather than on nothing.
|
|
586
|
-
|
|
587
|
-
|
|
956
|
+
const length = view?.duration ?? version.duration;
|
|
957
|
+
if (length !== null)
|
|
958
|
+
frame = Math.min(frame, Math.max(0, Math.ceil(length * fps - 1e-6) - 1));
|
|
588
959
|
const png = await jobs.frame(orig, frame / fps);
|
|
589
960
|
if (!png)
|
|
590
961
|
throw new RushesError(`ffmpeg couldn't read frame ${frame}`, 422, "no_frame", { frame });
|
|
@@ -622,12 +993,22 @@ export function createApp(store, opts = {}) {
|
|
|
622
993
|
});
|
|
623
994
|
app.put("/api/videos/:video/lock", async (c) => {
|
|
624
995
|
const b = await body(c, LockBody);
|
|
625
|
-
|
|
996
|
+
let before = null;
|
|
997
|
+
let films = 1;
|
|
998
|
+
const { result } = await store.update("project", (p) => {
|
|
999
|
+
before = resolveVideo(p, c.req.param("video")).lockedVersion;
|
|
1000
|
+
films = p.videos.length;
|
|
1001
|
+
return lockPicture(p, c.req.param("video"), b.version);
|
|
1002
|
+
});
|
|
1003
|
+
// R10: a lock that changes nothing isn't logged.
|
|
1004
|
+
if (result.lockedVersion !== before)
|
|
1005
|
+
await log.add(() => lockEvent(films, result), by(c));
|
|
626
1006
|
return c.json({ video: result });
|
|
627
1007
|
});
|
|
628
1008
|
app.post("/api/variants", async (c) => {
|
|
629
1009
|
const b = await body(c, VariantBody);
|
|
630
1010
|
const { result } = await store.update("project", (p) => addVariant(p, { ...b, file: toManifestPath(store.root, b.file) }));
|
|
1011
|
+
await log.add(() => variantEvent(result.lane, result.variant), by(c));
|
|
631
1012
|
return c.json(result, 201);
|
|
632
1013
|
});
|
|
633
1014
|
// ---- script ----
|
|
@@ -639,6 +1020,7 @@ export function createApp(store, opts = {}) {
|
|
|
639
1020
|
s.wordsPerSecond = b.wordsPerSecond;
|
|
640
1021
|
return setSections(s, b.sections, { replace: b.replace });
|
|
641
1022
|
});
|
|
1023
|
+
await log.add(() => scriptEvent(result.length), by(c));
|
|
642
1024
|
return c.json({ sections: result });
|
|
643
1025
|
});
|
|
644
1026
|
app.patch("/api/script/:id", async (c) => {
|
|
@@ -649,8 +1031,12 @@ export function createApp(store, opts = {}) {
|
|
|
649
1031
|
app.post("/api/script/:id/takes", async (c) => {
|
|
650
1032
|
const b = await body(c, TakeBody);
|
|
651
1033
|
const file = toManifestPath(store.root, b.file);
|
|
652
|
-
const info = await probe(fromManifestPath(store.root, file));
|
|
653
|
-
const { result } = await store.update("script", (s) => addTake(s, c.req.param("id"), { file, duration: info.duration }));
|
|
1034
|
+
const info = await probe(fromManifestPath(store.root, file), { formats: AUDIO_FORMATS });
|
|
1035
|
+
const { data, result } = await store.update("script", (s) => addTake(s, c.req.param("id"), { file, duration: info.duration }));
|
|
1036
|
+
await log.add(() => {
|
|
1037
|
+
const section = data.sections.find((s) => s.id === c.req.param("id"));
|
|
1038
|
+
return takeEvent(section, result, section.takes.findIndex((t) => t.id === result.id) + 1);
|
|
1039
|
+
}, by(c));
|
|
654
1040
|
return c.json({ take: result }, 201);
|
|
655
1041
|
});
|
|
656
1042
|
// ---- picks ----
|
|
@@ -666,7 +1052,9 @@ export function createApp(store, opts = {}) {
|
|
|
666
1052
|
into[k] = v;
|
|
667
1053
|
}
|
|
668
1054
|
};
|
|
1055
|
+
let before = {};
|
|
669
1056
|
const { data } = await store.update("picks", (p) => {
|
|
1057
|
+
before = { ...p.lanes };
|
|
670
1058
|
merge(p.lanes, b.lanes);
|
|
671
1059
|
merge(p.sections, b.sections);
|
|
672
1060
|
// §19.6: same merge rule as lanes/sections -- a number sets the level, null resets it to 0
|
|
@@ -681,6 +1069,16 @@ export function createApp(store, opts = {}) {
|
|
|
681
1069
|
p.levels[stage] = v;
|
|
682
1070
|
}
|
|
683
1071
|
});
|
|
1072
|
+
// §22.5: a change of what's picked is logged; levels alone aren't (R10).
|
|
1073
|
+
const changed = Object.keys({ ...before, ...data.lanes }).some((k) => before[k] !== data.lanes[k]);
|
|
1074
|
+
if (changed) {
|
|
1075
|
+
// The names come from project.json; if it can't be read now, the pick still stands (ruling e).
|
|
1076
|
+
const project = await store.read("project").catch(() => null);
|
|
1077
|
+
if (project)
|
|
1078
|
+
await log.add(() => picksEvent(project, data.lanes), by(c));
|
|
1079
|
+
else
|
|
1080
|
+
log.failures += 1;
|
|
1081
|
+
}
|
|
684
1082
|
return c.json(data);
|
|
685
1083
|
});
|
|
686
1084
|
// ---- mix loudness (§17.6) ----
|
|
@@ -699,7 +1097,15 @@ export function createApp(store, opts = {}) {
|
|
|
699
1097
|
const run = batchQueue.catch(() => undefined).then(async () => {
|
|
700
1098
|
const [project, script, batches] = await Promise.all([store.read("project"), store.read("script"), store.read("batches")]);
|
|
701
1099
|
const { result } = await store.update("notes", (notes) => createBatch({ project, script, notes, batches }, stage));
|
|
1100
|
+
// R11: the prompt ends with the last five lines of the log, from before this send. A log that
|
|
1101
|
+
// can't be read adds nothing: the notes are already marked as sent, so the batch must be kept.
|
|
1102
|
+
const recent = await Promise.all([store.read("project"), store.read("script")])
|
|
1103
|
+
.then(async ([projectNow, scriptNow]) => recentChanges((await log.view({ limit: 5 }, { project: projectNow, script: scriptNow })).entries))
|
|
1104
|
+
.catch(() => "");
|
|
1105
|
+
if (recent)
|
|
1106
|
+
result.prompt = `${result.prompt}\n\n${recent}`;
|
|
702
1107
|
await store.update("batches", (f) => { f.batches.push(result); });
|
|
1108
|
+
await log.add(() => notesSentEvent(result), by(c));
|
|
703
1109
|
return result;
|
|
704
1110
|
});
|
|
705
1111
|
batchQueue = run;
|
|
@@ -717,6 +1123,57 @@ export function createApp(store, opts = {}) {
|
|
|
717
1123
|
sections: script.sections.filter((s) => batch.sectionIds.includes(s.id)),
|
|
718
1124
|
});
|
|
719
1125
|
});
|
|
1126
|
+
// ---- the Change Log (§22.7) ----
|
|
1127
|
+
app.get("/api/log", async (c) => {
|
|
1128
|
+
const q = LogQuery.safeParse(c.req.query());
|
|
1129
|
+
if (!q.success)
|
|
1130
|
+
throw new InvalidError(q.error.issues.map((i) => i.message).join("; "), q.error.issues);
|
|
1131
|
+
const [project, script] = await Promise.all([store.read("project"), store.read("script")]);
|
|
1132
|
+
return c.json(await log.view(q.data, { project, script }));
|
|
1133
|
+
});
|
|
1134
|
+
app.post("/api/log", async (c) => {
|
|
1135
|
+
const b = await body(c, LogLineBody);
|
|
1136
|
+
// What's refused is named back on one clean line, never with the control characters it came with.
|
|
1137
|
+
const shown = (s) => Array.from(oneLineOf(s)).slice(0, 80).join("");
|
|
1138
|
+
const text = logText(b.text);
|
|
1139
|
+
if (!text)
|
|
1140
|
+
throw new InvalidError("text is empty: say what happened in one line");
|
|
1141
|
+
let video = null;
|
|
1142
|
+
let version = null;
|
|
1143
|
+
if (b.version && !b.video)
|
|
1144
|
+
throw new InvalidError("version needs video");
|
|
1145
|
+
// Read only when something must be checked against it, so a plain line never depends on project.json (M5).
|
|
1146
|
+
const project = b.video || b.ref ? await store.read("project") : null;
|
|
1147
|
+
if (project && b.video) {
|
|
1148
|
+
let v;
|
|
1149
|
+
try {
|
|
1150
|
+
v = resolveVideo(project, b.video);
|
|
1151
|
+
}
|
|
1152
|
+
catch {
|
|
1153
|
+
throw new NotFoundError("video", shown(b.video));
|
|
1154
|
+
}
|
|
1155
|
+
video = v.id;
|
|
1156
|
+
if (b.version) {
|
|
1157
|
+
if (!v.versions.some((x) => x.id === b.version))
|
|
1158
|
+
throw new NotFoundError("version", shown(b.version));
|
|
1159
|
+
version = b.version;
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
// A jump goes only to a variant ("<lane>/<variant>") or a take ("<section>:<take>") that exists.
|
|
1163
|
+
if (project && b.ref) {
|
|
1164
|
+
const script = await store.read("script");
|
|
1165
|
+
const refs = new Set([
|
|
1166
|
+
...project.lanes.flatMap((l) => l.variants.map((x) => `${l.id}/${x.id}`)),
|
|
1167
|
+
...script.sections.flatMap((s) => s.takes.map((x) => `${s.id}:${x.id}`)),
|
|
1168
|
+
]);
|
|
1169
|
+
if (!refs.has(b.ref))
|
|
1170
|
+
throw new NotFoundError("ref", shown(b.ref));
|
|
1171
|
+
}
|
|
1172
|
+
const entry = await log.add(() => lineEvent(text, b.area ?? "project", { video, version, ref: b.ref ?? null }), by(c));
|
|
1173
|
+
if (!entry)
|
|
1174
|
+
throw new RushesError("The Change Log couldn't be written. Run `rushes doctor`.", 500, "log_unwritable");
|
|
1175
|
+
return c.json({ entry }, 201);
|
|
1176
|
+
});
|
|
720
1177
|
// ---- live updates ----
|
|
721
1178
|
app.get("/api/events", (c) => streamSSE(c, async (stream) => {
|
|
722
1179
|
const send = (e) => void stream.writeSSE({ event: "change", data: JSON.stringify(e) });
|