drone-path 0.9.0 → 0.11.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/CHANGELOG.md +64 -0
- package/README.md +16 -14
- package/THIRD-PARTY-NOTICES.md +7 -7
- package/app/ipc.d.mts +43 -0
- package/app/ipc.mjs +216 -0
- package/app/main.mjs +10 -204
- package/dist/appsession.js +34 -75
- package/dist/appstate.js +24 -21
- package/dist/buildinfo.js +9 -16
- package/dist/cammeta-decode.js +237 -0
- package/dist/cammeta.js +8 -247
- package/dist/cli.js +40 -32
- package/dist/config.js +333 -173
- package/dist/configfile.js +20 -7
- package/dist/errors.js +30 -0
- package/dist/exec-tool.js +13 -0
- package/dist/exportjob.js +7 -7
- package/dist/{fftools.js → ffmpeg-tools.js} +5 -4
- package/dist/{ff.js → ffmpeg.js} +14 -29
- package/dist/frametime.js +32 -0
- package/dist/geo.js +1 -1
- package/dist/manual/build.js +5 -10
- package/dist/manual/cliref.js +4 -1
- package/dist/manual/reference.js +6 -11
- package/dist/{run.js → pipeline.js} +100 -143
- package/dist/png.js +1 -18
- package/dist/{proto.js → protobuf-wire.js} +5 -5
- package/dist/range.js +3 -3
- package/dist/{page.js → render-page.js} +2 -2
- package/dist/render.js +25 -115
- package/dist/renderer/boot.js +2 -2
- package/dist/renderer/dom.js +32 -10
- package/dist/renderer/scene.js +14 -6
- package/dist/restyle.js +1 -1
- package/dist/serve.js +1 -31
- package/dist/srt.js +2 -2
- package/dist/telemetry-json-schema.js +6 -11
- package/dist/telemetry-json.js +46 -27
- package/dist/telemetry-math.js +3 -2
- package/dist/{summary.js → telemetry-summary.js} +4 -4
- package/dist/telemetry.js +32 -18
- package/dist/tiles.js +30 -86
- package/dist/track-format.js +13 -0
- package/dist/track-geojson.js +44 -0
- package/dist/track-gpx.js +34 -0
- package/dist/track-kml.js +47 -0
- package/dist/track-kmz.js +68 -0
- package/dist/track-write.js +41 -0
- package/dist/track.js +79 -0
- package/package.json +13 -14
- package/dist/tracing.js +0 -184
- /package/dist/{renderer/leaflet.js → logging.js} +0 -0
- /package/dist/{inputs.js → recordings.js} +0 -0
package/app/main.mjs
CHANGED
|
@@ -9,7 +9,7 @@ import process from 'node:process';
|
|
|
9
9
|
import { Readable } from 'node:stream';
|
|
10
10
|
import { pathToFileURL } from 'node:url';
|
|
11
11
|
|
|
12
|
-
import { app, BrowserWindow, dialog,
|
|
12
|
+
import { app, BrowserWindow, dialog, Menu, net, protocol, shell } from 'electron';
|
|
13
13
|
|
|
14
14
|
import { resolveAppAsset } from '../dist/appassets.js';
|
|
15
15
|
import { APP_ORIGIN, appStateFile, uiExportRoot } from '../dist/apppaths.js';
|
|
@@ -20,17 +20,15 @@ import {
|
|
|
20
20
|
rememberOpenedFile,
|
|
21
21
|
writeAppState,
|
|
22
22
|
} from '../dist/appstate.js';
|
|
23
|
-
import { createAppSession
|
|
24
|
-
import { parseExportRequest, parseSettingsPatch } from '../dist/config.js';
|
|
23
|
+
import { createAppSession } from '../dist/appsession.js';
|
|
25
24
|
import { resolveConfig } from '../dist/configfile.js';
|
|
26
25
|
import { ERROR_PREFIX, errorMessage } from '../dist/errors.js';
|
|
27
26
|
import { createExportRunner } from '../dist/exportjob.js';
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
import { rangePlan } from '../dist/range.js';
|
|
32
|
-
import { outputPathFor } from '../dist/run.js';
|
|
27
|
+
import { requireFfmpegTools } from '../dist/ffmpeg.js';
|
|
28
|
+
import { resolveFfmpegTools } from '../dist/ffmpeg-tools.js';
|
|
29
|
+
import { planByteRange } from '../dist/range.js';
|
|
33
30
|
import { createTileTraffic } from '../dist/tiles.js';
|
|
31
|
+
import { registerIpcHandlers } from './ipc.mjs';
|
|
34
32
|
import { initUpdates } from './update.mjs';
|
|
35
33
|
|
|
36
34
|
const SCHEME = 'app';
|
|
@@ -136,7 +134,7 @@ function handleExportDone(state, outcome) {
|
|
|
136
134
|
|
|
137
135
|
function videoResponse(request, filePath) {
|
|
138
136
|
const size = fs.statSync(filePath).size;
|
|
139
|
-
const plan =
|
|
137
|
+
const plan = planByteRange(request.headers.get('range') ?? undefined, size, 'video/mp4');
|
|
140
138
|
if (plan.status === 416) {
|
|
141
139
|
return new Response(plan.body, { status: 416, headers: plan.headers });
|
|
142
140
|
}
|
|
@@ -191,52 +189,13 @@ async function handleRequest(state, request) {
|
|
|
191
189
|
}
|
|
192
190
|
}
|
|
193
191
|
|
|
194
|
-
// Only this app's window may drive the session state machine.
|
|
195
|
-
function assertTrusted(event) {
|
|
196
|
-
const url = (event.senderFrame && event.senderFrame.url) || '';
|
|
197
|
-
const devOk = DEV_URL !== null && url.startsWith(DEV_URL);
|
|
198
|
-
if (!url.startsWith(APP_ORIGIN + '/') && !devOk) {
|
|
199
|
-
throw new Error('untrusted ipc sender');
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// The reveal/open guard: the renderer may only name a file this shell wrote
|
|
204
|
-
// (the last export or the last telemetry document, both set only by trusted
|
|
205
|
-
// handlers), never an arbitrary path.
|
|
206
|
-
function knownOutputOf(state, payload) {
|
|
207
|
-
const out = payload && typeof payload === 'object' ? payload.out : null;
|
|
208
|
-
if (typeof out !== 'string' || (out !== state.lastExportOut && out !== state.lastTelemetryOut)) {
|
|
209
|
-
throw new Error('unknown output');
|
|
210
|
-
}
|
|
211
|
-
return out;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// The native dialog confirmed the name as typed, but the extension may have
|
|
215
|
-
// been appended after it: re-check the final path on every platform so an
|
|
216
|
-
// existing file is never replaced without a confirmation.
|
|
217
|
-
async function confirmReplace(state, chosen) {
|
|
218
|
-
if (!fs.existsSync(chosen)) return true;
|
|
219
|
-
const box = {
|
|
220
|
-
type: 'warning',
|
|
221
|
-
buttons: ['Replace', 'Cancel'],
|
|
222
|
-
defaultId: 1,
|
|
223
|
-
cancelId: 1,
|
|
224
|
-
message: `Replace ${path.basename(chosen)}?`,
|
|
225
|
-
detail: chosen,
|
|
226
|
-
};
|
|
227
|
-
const confirm = state.win
|
|
228
|
-
? await dialog.showMessageBox(state.win, box)
|
|
229
|
-
: await dialog.showMessageBox(box);
|
|
230
|
-
return confirm.response === 0;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
192
|
// The backing services behind the window: tool check, config, tile cache and
|
|
234
193
|
// the recording session.
|
|
235
194
|
async function initServices(state) {
|
|
236
195
|
const resolved = resolveConfig({});
|
|
237
196
|
state.appState = readAppState(appStateFile());
|
|
238
197
|
state.config = applyAppState(resolved.config, state.appState);
|
|
239
|
-
await
|
|
198
|
+
await requireFfmpegTools(resolveFfmpegTools(state.config));
|
|
240
199
|
// One polite tile queue for the whole app: on-demand tiles and the export
|
|
241
200
|
// prefetch share its request budget, and on-demand tiles the player needs
|
|
242
201
|
// right now jump the queue.
|
|
@@ -266,159 +225,6 @@ function initExportRunner(state) {
|
|
|
266
225
|
});
|
|
267
226
|
}
|
|
268
227
|
|
|
269
|
-
function registerIpcHandlers(state) {
|
|
270
|
-
ipcMain.handle('dronepath:pick', (event, raw) => {
|
|
271
|
-
assertTrusted(event);
|
|
272
|
-
try {
|
|
273
|
-
return state.session.pick(parsePickRequest(raw));
|
|
274
|
-
} catch (e) {
|
|
275
|
-
return { ok: false, error: errorMessage(e) };
|
|
276
|
-
}
|
|
277
|
-
});
|
|
278
|
-
ipcMain.handle('dronepath:session', (event) => {
|
|
279
|
-
assertTrusted(event);
|
|
280
|
-
return state.session.getSession();
|
|
281
|
-
});
|
|
282
|
-
ipcMain.handle('dronepath:settings', (event) => {
|
|
283
|
-
assertTrusted(event);
|
|
284
|
-
return state.config;
|
|
285
|
-
});
|
|
286
|
-
ipcMain.handle('dronepath:settings:save', (event, raw) => {
|
|
287
|
-
assertTrusted(event);
|
|
288
|
-
let settings;
|
|
289
|
-
try {
|
|
290
|
-
settings = parseSettingsPatch(raw, 'settings');
|
|
291
|
-
} catch (e) {
|
|
292
|
-
return { ok: false, error: errorMessage(e) };
|
|
293
|
-
}
|
|
294
|
-
state.appState = { ...state.appState, settings };
|
|
295
|
-
state.config = applyAppState(state.config, state.appState);
|
|
296
|
-
try {
|
|
297
|
-
writeAppState(appStateFile(), state.appState);
|
|
298
|
-
} catch (e) {
|
|
299
|
-
// The look still applies when the state file cannot be written.
|
|
300
|
-
log(`app state not saved: ${errorMessage(e)}`);
|
|
301
|
-
}
|
|
302
|
-
return { ok: true };
|
|
303
|
-
});
|
|
304
|
-
|
|
305
|
-
ipcMain.handle('dronepath:export:pick-output', async (event) => {
|
|
306
|
-
assertTrusted(event);
|
|
307
|
-
const video = state.session ? state.session.videoPath() : null;
|
|
308
|
-
if (!video) return { ok: false, error: 'no recording loaded' };
|
|
309
|
-
// The CLI's default naming, with a relative out dir anchored at the
|
|
310
|
-
// recording: the app process has no meaningful working directory.
|
|
311
|
-
const outDir = state.config.outDir
|
|
312
|
-
? path.resolve(path.dirname(video), state.config.outDir)
|
|
313
|
-
: null;
|
|
314
|
-
const options = {
|
|
315
|
-
title: 'Export video',
|
|
316
|
-
defaultPath: outputPathFor(video, { ...state.config, outDir }),
|
|
317
|
-
filters: [{ name: 'MP4 video', extensions: ['mp4'] }],
|
|
318
|
-
};
|
|
319
|
-
const result = state.win
|
|
320
|
-
? await dialog.showSaveDialog(state.win, options)
|
|
321
|
-
: await dialog.showSaveDialog(options);
|
|
322
|
-
if (result.canceled || !result.filePath) return { ok: false, canceled: true };
|
|
323
|
-
const chosen = result.filePath.toLowerCase().endsWith('.mp4')
|
|
324
|
-
? result.filePath
|
|
325
|
-
: `${result.filePath}.mp4`;
|
|
326
|
-
if (!(await confirmReplace(state, chosen))) return { ok: false, canceled: true };
|
|
327
|
-
return { ok: true, path: chosen };
|
|
328
|
-
});
|
|
329
|
-
ipcMain.handle('dronepath:telemetry:pick-output', async (event) => {
|
|
330
|
-
assertTrusted(event);
|
|
331
|
-
const video = state.session ? state.session.videoPath() : null;
|
|
332
|
-
if (!video) return { ok: false, error: 'no recording loaded' };
|
|
333
|
-
// The export dialog's default folder, named after the recording
|
|
334
|
-
// (<basename>.telemetry.json).
|
|
335
|
-
const outDir = state.config.outDir
|
|
336
|
-
? path.resolve(path.dirname(video), state.config.outDir)
|
|
337
|
-
: null;
|
|
338
|
-
const exportDefault = outputPathFor(video, { ...state.config, outDir });
|
|
339
|
-
const options = {
|
|
340
|
-
title: 'Export telemetry',
|
|
341
|
-
defaultPath: path.join(path.dirname(exportDefault), `${videoBaseName(video)}.telemetry.json`),
|
|
342
|
-
filters: [{ name: 'JSON document', extensions: ['json'] }],
|
|
343
|
-
};
|
|
344
|
-
const result = state.win
|
|
345
|
-
? await dialog.showSaveDialog(state.win, options)
|
|
346
|
-
: await dialog.showSaveDialog(options);
|
|
347
|
-
if (result.canceled || !result.filePath) return { ok: false, canceled: true };
|
|
348
|
-
const chosen = result.filePath.toLowerCase().endsWith('.json')
|
|
349
|
-
? result.filePath
|
|
350
|
-
: `${result.filePath}.json`;
|
|
351
|
-
if (!(await confirmReplace(state, chosen))) return { ok: false, canceled: true };
|
|
352
|
-
return { ok: true, path: chosen };
|
|
353
|
-
});
|
|
354
|
-
ipcMain.handle('dronepath:telemetry:save', (event, raw) => {
|
|
355
|
-
assertTrusted(event);
|
|
356
|
-
try {
|
|
357
|
-
const video = state.session ? state.session.videoPath() : null;
|
|
358
|
-
if (!video) return { ok: false, error: 'no recording loaded' };
|
|
359
|
-
const request = parseTelemetrySaveRequest(raw);
|
|
360
|
-
state.session.saveTelemetryJson(request.outPath, request.range);
|
|
361
|
-
state.lastTelemetryOut = request.outPath;
|
|
362
|
-
log(`telemetry JSON: wrote ${request.outPath}`);
|
|
363
|
-
return { ok: true };
|
|
364
|
-
} catch (e) {
|
|
365
|
-
return { ok: false, error: errorMessage(e) };
|
|
366
|
-
}
|
|
367
|
-
});
|
|
368
|
-
ipcMain.handle('dronepath:export:start', (event, raw) => {
|
|
369
|
-
assertTrusted(event);
|
|
370
|
-
try {
|
|
371
|
-
const video = state.session ? state.session.videoPath() : null;
|
|
372
|
-
if (!video) return { ok: false, error: 'no recording loaded' };
|
|
373
|
-
state.exportRunner.start(video, parseExportRequest(raw, state.config));
|
|
374
|
-
return { ok: true };
|
|
375
|
-
} catch (e) {
|
|
376
|
-
return { ok: false, error: errorMessage(e) };
|
|
377
|
-
}
|
|
378
|
-
});
|
|
379
|
-
ipcMain.handle('dronepath:export:cancel', (event) => {
|
|
380
|
-
assertTrusted(event);
|
|
381
|
-
state.exportRunner.cancel();
|
|
382
|
-
return { ok: true };
|
|
383
|
-
});
|
|
384
|
-
ipcMain.handle('dronepath:export:reveal', (event, payload) => {
|
|
385
|
-
assertTrusted(event);
|
|
386
|
-
try {
|
|
387
|
-
shell.showItemInFolder(knownOutputOf(state, payload));
|
|
388
|
-
return { ok: true };
|
|
389
|
-
} catch (e) {
|
|
390
|
-
return { ok: false, error: errorMessage(e) };
|
|
391
|
-
}
|
|
392
|
-
});
|
|
393
|
-
ipcMain.handle('dronepath:export:open', async (event, payload) => {
|
|
394
|
-
assertTrusted(event);
|
|
395
|
-
try {
|
|
396
|
-
const error = await shell.openPath(knownOutputOf(state, payload));
|
|
397
|
-
return error ? { ok: false, error } : { ok: true };
|
|
398
|
-
} catch (e) {
|
|
399
|
-
return { ok: false, error: errorMessage(e) };
|
|
400
|
-
}
|
|
401
|
-
});
|
|
402
|
-
ipcMain.handle('dronepath:update:restart', (event) => {
|
|
403
|
-
assertTrusted(event);
|
|
404
|
-
if (!state.updates) return { ok: false, error: 'this build does not self-update' };
|
|
405
|
-
// No pendingClose here: the prompt never opens over a running export, and
|
|
406
|
-
// a failed restart must not poison the export close guard.
|
|
407
|
-
return state.updates.restart({
|
|
408
|
-
onError: (message) => sendToWindow(state, 'dronepath:update:restart-failed', message),
|
|
409
|
-
});
|
|
410
|
-
});
|
|
411
|
-
ipcMain.handle('dronepath:update:state', (event) => {
|
|
412
|
-
assertTrusted(event);
|
|
413
|
-
return { ready: state.updateReady };
|
|
414
|
-
});
|
|
415
|
-
ipcMain.handle('dronepath:window:close', (event) => {
|
|
416
|
-
assertTrusted(event);
|
|
417
|
-
// The window's close handler runs the running-export guard.
|
|
418
|
-
if (state.win && !state.win.isDestroyed()) state.win.close();
|
|
419
|
-
});
|
|
420
|
-
}
|
|
421
|
-
|
|
422
228
|
function installProtocolHandler(state) {
|
|
423
229
|
protocol.handle(SCHEME, (request) =>
|
|
424
230
|
handleRequest(state, request).catch((e) => {
|
|
@@ -491,7 +297,7 @@ function installCloseGuard(state) {
|
|
|
491
297
|
defaultId: 1,
|
|
492
298
|
cancelId: 1,
|
|
493
299
|
message: 'An export is in progress',
|
|
494
|
-
detail: 'Closing the window stops the export and removes its
|
|
300
|
+
detail: 'Closing the window stops the export and removes its unfinished file.',
|
|
495
301
|
};
|
|
496
302
|
void (state.win ? dialog.showMessageBox(state.win, box) : dialog.showMessageBox(box)).then(
|
|
497
303
|
({ response }) => {
|
|
@@ -536,7 +342,7 @@ async function startup() {
|
|
|
536
342
|
sendToWindow(state, 'dronepath:update:ready');
|
|
537
343
|
},
|
|
538
344
|
});
|
|
539
|
-
registerIpcHandlers(state);
|
|
345
|
+
registerIpcHandlers(state, { devUrl: DEV_URL, log, sendToWindow });
|
|
540
346
|
installProtocolHandler(state);
|
|
541
347
|
ensureUiExport();
|
|
542
348
|
createWindow(state);
|
package/dist/appsession.js
CHANGED
|
@@ -1,72 +1,44 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
+
import { z } from 'zod';
|
|
3
4
|
import { TILE_BASE, mediaUrlFor } from './apppaths.js';
|
|
4
|
-
import {
|
|
5
|
-
import { errorMessage } from './errors.js';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
5
|
+
import { parseFrameRange, parseAppearanceSettings, parseValue, strictShape, } from './config.js';
|
|
6
|
+
import { ERR_NO_RECORDING, ERR_NOT_READABLE_MP4, errorMessage } from './errors.js';
|
|
7
|
+
import { timeAt } from './frametime.js';
|
|
8
|
+
import { isRecordingName } from './recordings.js';
|
|
9
|
+
import { buildSceneData } from './render-page.js';
|
|
10
|
+
import { prepareSession, recordingPageOpts, telemetryExportInput, trackExportStream, } from './pipeline.js';
|
|
11
|
+
import { trackFormatOf } from './track-format.js';
|
|
12
|
+
import { writeTrackFile } from './track-write.js';
|
|
10
13
|
export function frameExactDuration(probe) {
|
|
11
|
-
return probe.frames
|
|
14
|
+
return timeAt(probe.frames, probe.fps.value);
|
|
12
15
|
}
|
|
13
16
|
export function parsePickRequest(raw) {
|
|
14
17
|
const input = typeof raw === 'object' && raw !== null ? raw : {};
|
|
15
|
-
|
|
16
|
-
? input.settings
|
|
17
|
-
: {};
|
|
18
|
-
const { style, view, hud } = look;
|
|
19
|
-
if (typeof style !== 'string' || !STYLE_VALUES.includes(style)) {
|
|
20
|
-
throw new Error(`unknown map style: ${String(style)}`);
|
|
21
|
-
}
|
|
22
|
-
if (typeof view !== 'string' || !VIEW_VALUES.includes(view)) {
|
|
23
|
-
throw new Error(`unknown view: ${String(view)}`);
|
|
24
|
-
}
|
|
25
|
-
const zoom = asNumber(look.zoom, 'zoom');
|
|
26
|
-
const zoomOut = asNumber(look.zoomOut, 'zoom-out');
|
|
27
|
-
if (!(zoom >= 0))
|
|
28
|
-
throw new Error('zoom must be >= 0 (0 = auto-fit)');
|
|
29
|
-
if (!(zoomOut >= 0))
|
|
30
|
-
throw new Error('zoom-out must be >= 0');
|
|
31
|
-
const introSec = asNumber(look.introSec, 'intro');
|
|
32
|
-
const outroSec = asNumber(look.outroSec, 'outro');
|
|
33
|
-
if (!(introSec >= 0))
|
|
34
|
-
throw new Error('intro must be 0 or more');
|
|
35
|
-
if (!(outroSec >= 0))
|
|
36
|
-
throw new Error('outro must be 0 or more');
|
|
37
|
-
const trailColor = asTrailColor(look.trailColor ?? null, 'trail color');
|
|
38
|
-
const chips = typeof hud === 'object' && hud !== null ? hud : {};
|
|
39
|
-
return {
|
|
40
|
-
settings: {
|
|
41
|
-
style: style,
|
|
42
|
-
view: view,
|
|
43
|
-
zoom,
|
|
44
|
-
zoomOut,
|
|
45
|
-
hud: { heading: !!chips.heading, alt: !!chips.alt, speed: !!chips.speed },
|
|
46
|
-
introSec,
|
|
47
|
-
outroSec,
|
|
48
|
-
trailColor,
|
|
49
|
-
},
|
|
50
|
-
};
|
|
18
|
+
return { settings: parseAppearanceSettings(input.settings) };
|
|
51
19
|
}
|
|
20
|
+
const TELEMETRY_SAVE_SHAPE = {
|
|
21
|
+
outPath: z.unknown().optional(),
|
|
22
|
+
range: z.unknown().optional(),
|
|
23
|
+
};
|
|
52
24
|
export function parseTelemetrySaveRequest(raw) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (typeof r.outPath !== 'string' || !r.outPath) {
|
|
63
|
-
throw new Error('invalid telemetry save request: outPath');
|
|
25
|
+
const request = parseValue(strictShape(TELEMETRY_SAVE_SHAPE, {
|
|
26
|
+
invalid: 'invalid telemetry save request',
|
|
27
|
+
unknownKey: (key) => `unknown telemetry save request key ${key}`,
|
|
28
|
+
}), raw);
|
|
29
|
+
const outPath = parseValue(z
|
|
30
|
+
.string({ error: () => 'invalid telemetry save request: outPath' })
|
|
31
|
+
.min(1, { error: () => 'invalid telemetry save request: outPath' }), request.outPath);
|
|
32
|
+
try {
|
|
33
|
+
trackFormatOf(outPath);
|
|
64
34
|
}
|
|
65
|
-
|
|
66
|
-
throw new Error(`invalid telemetry save request: outPath must be a .json file: ${
|
|
35
|
+
catch (e) {
|
|
36
|
+
throw new Error(`invalid telemetry save request: outPath must be a .gpx, .geojson, .kml, .kmz or .json file: ${outPath}`, { cause: e });
|
|
67
37
|
}
|
|
68
|
-
const range =
|
|
69
|
-
|
|
38
|
+
const range = request.range === undefined || request.range === null
|
|
39
|
+
? null
|
|
40
|
+
: parseFrameRange(request.range);
|
|
41
|
+
return { outPath, range };
|
|
70
42
|
}
|
|
71
43
|
export const prepareUiSession = async (videoPath, config, log, onProgress, deps) => {
|
|
72
44
|
const prep = await prepareSession(videoPath, config, log, {
|
|
@@ -88,6 +60,7 @@ export const prepareUiSession = async (videoPath, config, log, onProgress, deps)
|
|
|
88
60
|
durationSec: frameExactDuration(prep.probe),
|
|
89
61
|
},
|
|
90
62
|
telemetry: telemetryExportInput(prep),
|
|
63
|
+
track: trackExportStream(prep),
|
|
91
64
|
};
|
|
92
65
|
};
|
|
93
66
|
function isReadableVideo(filePath) {
|
|
@@ -100,18 +73,6 @@ function isReadableVideo(filePath) {
|
|
|
100
73
|
return false;
|
|
101
74
|
}
|
|
102
75
|
}
|
|
103
|
-
function segmentTelemetryInput(input, range) {
|
|
104
|
-
const segment = resolveRange(range, input.frameCount);
|
|
105
|
-
if (!segment)
|
|
106
|
-
return input;
|
|
107
|
-
return {
|
|
108
|
-
...input,
|
|
109
|
-
frameCount: segment.end - segment.start + 1,
|
|
110
|
-
frames: input.frames.slice(segment.start, segment.end + 1),
|
|
111
|
-
headingDeg: input.headingDeg.slice(segment.start, segment.end + 1),
|
|
112
|
-
frameStart: segment.start,
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
76
|
export function createAppSession(options) {
|
|
116
77
|
const { config, pickFile } = options;
|
|
117
78
|
const prepare = options.prepare ?? prepareUiSession;
|
|
@@ -133,7 +94,7 @@ export function createAppSession(options) {
|
|
|
133
94
|
const resolved = path.resolve(picked);
|
|
134
95
|
if (!isReadableVideo(resolved)) {
|
|
135
96
|
log(`rejected: ${resolved}`);
|
|
136
|
-
return { ok: false, error:
|
|
97
|
+
return { ok: false, error: `${ERR_NOT_READABLE_MP4}${resolved}` };
|
|
137
98
|
}
|
|
138
99
|
onPreparing(resolved);
|
|
139
100
|
prepared = await prepare(resolved, { ...config, ...request.settings }, log, onPrepareProgress);
|
|
@@ -153,10 +114,8 @@ export function createAppSession(options) {
|
|
|
153
114
|
videoPath: () => videoPath,
|
|
154
115
|
saveTelemetryJson(file, range) {
|
|
155
116
|
if (!prepared)
|
|
156
|
-
throw new Error(
|
|
157
|
-
|
|
158
|
-
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
159
|
-
fs.writeFileSync(file, serializeTelemetryDocument(doc));
|
|
117
|
+
throw new Error(ERR_NO_RECORDING);
|
|
118
|
+
writeTrackFile(file, { document: prepared.telemetry, track: prepared.track }, range);
|
|
160
119
|
},
|
|
161
120
|
};
|
|
162
121
|
}
|
package/dist/appstate.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import {
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { DEFAULT_CONFIG, SETTINGS_KEYS, formatHud, parseSettingsPatch, parseValue, strictShape, } from './config.js';
|
|
5
|
+
import { errorMessage } from './errors.js';
|
|
4
6
|
export const APP_STATE_VERSION = 1;
|
|
5
7
|
export function emptyAppState() {
|
|
6
8
|
return { settings: null, lastOpenDir: null };
|
|
@@ -15,27 +17,28 @@ function fillMissingSettings(raw) {
|
|
|
15
17
|
}
|
|
16
18
|
return filled;
|
|
17
19
|
}
|
|
20
|
+
const APP_STATE_SHAPE = {
|
|
21
|
+
version: z.unknown().optional(),
|
|
22
|
+
settings: z.unknown().optional(),
|
|
23
|
+
lastOpenDir: z.unknown().optional(),
|
|
24
|
+
};
|
|
25
|
+
const LAST_OPEN_DIR = z
|
|
26
|
+
.optional(z.nullable(z.string({
|
|
27
|
+
error: (issue) => `invalid app state: lastOpenDir: ${String(issue.input)}`,
|
|
28
|
+
})))
|
|
29
|
+
.transform((value) => value ?? null);
|
|
18
30
|
export function parseAppState(raw) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
if (r.version !== APP_STATE_VERSION) {
|
|
29
|
-
throw new Error(`unsupported app state version: ${String(r.version)}`);
|
|
30
|
-
}
|
|
31
|
-
const settings = r.settings === undefined || r.settings === null
|
|
31
|
+
const state = parseValue(strictShape(APP_STATE_SHAPE, {
|
|
32
|
+
invalid: 'invalid app state',
|
|
33
|
+
unknownKey: (key) => `unknown app state key ${key}`,
|
|
34
|
+
}), raw);
|
|
35
|
+
parseValue(z.literal(APP_STATE_VERSION, {
|
|
36
|
+
error: (issue) => `unsupported app state version: ${String(issue.input)}`,
|
|
37
|
+
}), state.version);
|
|
38
|
+
const settings = state.settings === undefined || state.settings === null
|
|
32
39
|
? null
|
|
33
|
-
: parseSettingsPatch(fillMissingSettings(
|
|
34
|
-
|
|
35
|
-
throw new Error(`invalid app state: lastOpenDir: ${String(r.lastOpenDir)}`);
|
|
36
|
-
}
|
|
37
|
-
const lastOpenDir = typeof r.lastOpenDir === 'string' ? r.lastOpenDir : null;
|
|
38
|
-
return { settings, lastOpenDir };
|
|
40
|
+
: parseSettingsPatch(fillMissingSettings(state.settings), 'app state');
|
|
41
|
+
return { settings, lastOpenDir: parseValue(LAST_OPEN_DIR, state.lastOpenDir) };
|
|
39
42
|
}
|
|
40
43
|
export function serializeAppState(state) {
|
|
41
44
|
const out = { version: APP_STATE_VERSION };
|
|
@@ -84,7 +87,7 @@ export function writeAppState(file, state) {
|
|
|
84
87
|
fs.writeFileSync(file, serializeAppState(state));
|
|
85
88
|
}
|
|
86
89
|
catch (e) {
|
|
87
|
-
throw new Error(`cannot write app state ${file}: ${e
|
|
90
|
+
throw new Error(`cannot write app state ${file}: ${errorMessage(e)}`, {
|
|
88
91
|
cause: e,
|
|
89
92
|
});
|
|
90
93
|
}
|
package/dist/buildinfo.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { execFile } from 'node:child_process';
|
|
2
1
|
import fs from 'node:fs';
|
|
3
2
|
import path from 'node:path';
|
|
4
3
|
import { fileURLToPath } from 'node:url';
|
|
5
|
-
import {
|
|
4
|
+
import { runToolMain } from './errors.js';
|
|
5
|
+
import { runTool } from './exec-tool.js';
|
|
6
6
|
import { VERSION } from './version.js';
|
|
7
|
-
const execFileAsync = promisify(execFile);
|
|
8
7
|
export function defaultBuildinfoPaths(root) {
|
|
9
8
|
return {
|
|
10
9
|
moduleFile: path.join(root, 'ui', 'lib', 'buildinfo', 'generated', 'buildinfo.ts'),
|
|
@@ -33,14 +32,14 @@ export function buildBuildinfo(paths, version, probe) {
|
|
|
33
32
|
}
|
|
34
33
|
async function tryGit(args) {
|
|
35
34
|
try {
|
|
36
|
-
const { stdout } = await
|
|
35
|
+
const { stdout } = await runTool('git', [...args]);
|
|
37
36
|
return stdout;
|
|
38
37
|
}
|
|
39
38
|
catch {
|
|
40
39
|
return null;
|
|
41
40
|
}
|
|
42
41
|
}
|
|
43
|
-
|
|
42
|
+
async function probeGit() {
|
|
44
43
|
const head = await tryGit(['rev-parse', 'HEAD']);
|
|
45
44
|
if (head === null)
|
|
46
45
|
return null;
|
|
@@ -55,17 +54,11 @@ export async function probeGit() {
|
|
|
55
54
|
};
|
|
56
55
|
}
|
|
57
56
|
async function main() {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
process.stderr.write(`[drone-path] buildinfo: ${VERSION} (${detail})\n`);
|
|
63
|
-
}
|
|
64
|
-
catch (e) {
|
|
65
|
-
process.stderr.write(`[drone-path] ERROR: ${e.message}\n`);
|
|
66
|
-
process.exitCode = 1;
|
|
67
|
-
}
|
|
57
|
+
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
58
|
+
const git = buildBuildinfo(defaultBuildinfoPaths(root), VERSION, await probeGit());
|
|
59
|
+
const detail = git === null ? 'no git' : git.tagged ? 'tagged' : `commit ${git.commit}`;
|
|
60
|
+
process.stderr.write(`[drone-path] buildinfo: ${VERSION} (${detail})\n`);
|
|
68
61
|
}
|
|
69
62
|
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
70
|
-
void main
|
|
63
|
+
void runToolMain(main);
|
|
71
64
|
}
|