drone-path 0.12.1 → 1.0.0-rc1

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.
Files changed (78) hide show
  1. package/README.md +20 -74
  2. package/THIRD-PARTY-NOTICES.md +3 -82
  3. package/bin/drone-path.mjs +0 -0
  4. package/dist/cli.d.ts +14 -0
  5. package/dist/cli.js +7 -7
  6. package/dist/version.d.ts +1 -0
  7. package/package.json +21 -68
  8. package/CHANGELOG.md +0 -336
  9. package/app/ipc.d.mts +0 -43
  10. package/app/ipc.mjs +0 -216
  11. package/app/main.mjs +0 -356
  12. package/app/preload.cjs +0 -34
  13. package/app/update-policy.d.mts +0 -6
  14. package/app/update-policy.mjs +0 -6
  15. package/app/update.d.mts +0 -10
  16. package/app/update.mjs +0 -54
  17. package/dist/appassets.js +0 -35
  18. package/dist/apppaths.js +0 -20
  19. package/dist/appsession.js +0 -121
  20. package/dist/appstate.js +0 -94
  21. package/dist/assets.js +0 -60
  22. package/dist/buildinfo.js +0 -64
  23. package/dist/cammeta-decode.js +0 -237
  24. package/dist/cammeta.js +0 -92
  25. package/dist/changeset-gate.js +0 -39
  26. package/dist/config.js +0 -631
  27. package/dist/configfile.js +0 -86
  28. package/dist/decimate.js +0 -84
  29. package/dist/errors.js +0 -34
  30. package/dist/exec-tool.js +0 -13
  31. package/dist/exportjob.js +0 -90
  32. package/dist/ffmpeg-tools.js +0 -56
  33. package/dist/ffmpeg.js +0 -98
  34. package/dist/frametime.js +0 -32
  35. package/dist/geo.js +0 -60
  36. package/dist/logging.js +0 -1
  37. package/dist/manual/anchors.js +0 -17
  38. package/dist/manual/build.js +0 -67
  39. package/dist/manual/cliref.js +0 -34
  40. package/dist/manual/links.js +0 -59
  41. package/dist/manual/markdown.js +0 -98
  42. package/dist/manual/model.js +0 -1
  43. package/dist/manual/module.js +0 -5
  44. package/dist/manual/nav.js +0 -11
  45. package/dist/manual/reference.js +0 -18
  46. package/dist/paths.js +0 -16
  47. package/dist/pipeline.js +0 -402
  48. package/dist/plan.js +0 -106
  49. package/dist/png.js +0 -32
  50. package/dist/protobuf-wire.js +0 -102
  51. package/dist/range.js +0 -50
  52. package/dist/recordings.js +0 -55
  53. package/dist/render-page.js +0 -85
  54. package/dist/render.js +0 -268
  55. package/dist/renderer/boot.js +0 -7
  56. package/dist/renderer/dom.js +0 -177
  57. package/dist/renderer/framemath.js +0 -30
  58. package/dist/renderer/scene.js +0 -385
  59. package/dist/renderer/theme.js +0 -82
  60. package/dist/renderer/tilesources.js +0 -38
  61. package/dist/renderer/trail.js +0 -42
  62. package/dist/restyle.js +0 -16
  63. package/dist/serve.js +0 -27
  64. package/dist/srt.js +0 -98
  65. package/dist/telemetry-json-schema.js +0 -18
  66. package/dist/telemetry-json.js +0 -126
  67. package/dist/telemetry-math.js +0 -267
  68. package/dist/telemetry-summary.js +0 -19
  69. package/dist/telemetry.js +0 -95
  70. package/dist/tilecache.js +0 -21
  71. package/dist/tiles.js +0 -155
  72. package/dist/track-format.js +0 -13
  73. package/dist/track-geojson.js +0 -44
  74. package/dist/track-gpx.js +0 -34
  75. package/dist/track-kml.js +0 -47
  76. package/dist/track-kmz.js +0 -68
  77. package/dist/track-write.js +0 -41
  78. package/dist/track.js +0 -79
package/app/main.mjs DELETED
@@ -1,356 +0,0 @@
1
- #!/usr/bin/env node
2
- // Electron shell for the Drone Path desktop app: window, native file
3
- // dialog, the app:// scheme and process lifecycle only. All behavior lives in
4
- // dist/ (compiled from src/), so the app and the CLI stay one code base.
5
-
6
- import fs from 'node:fs';
7
- import path from 'node:path';
8
- import process from 'node:process';
9
- import { Readable } from 'node:stream';
10
- import { pathToFileURL } from 'node:url';
11
-
12
- import { app, BrowserWindow, dialog, Menu, net, protocol, shell } from 'electron';
13
-
14
- import { resolveAppAsset } from '../dist/appassets.js';
15
- import { APP_ORIGIN, appStateFile, uiExportRoot } from '../dist/apppaths.js';
16
- import {
17
- applyAppState,
18
- emptyAppState,
19
- readAppState,
20
- rememberOpenedFile,
21
- writeAppState,
22
- } from '../dist/appstate.js';
23
- import { createAppSession } from '../dist/appsession.js';
24
- import { resolveConfig } from '../dist/configfile.js';
25
- import { ERROR_PREFIX, errorMessage } from '../dist/errors.js';
26
- import { createExportRunner } from '../dist/exportjob.js';
27
- import { requireFfmpegTools } from '../dist/ffmpeg.js';
28
- import { resolveFfmpegTools } from '../dist/ffmpeg-tools.js';
29
- import { planByteRange } from '../dist/range.js';
30
- import { createTileTraffic } from '../dist/tiles.js';
31
- import { registerIpcHandlers } from './ipc.mjs';
32
- import { initUpdates } from './update.mjs';
33
-
34
- const SCHEME = 'app';
35
- // --dev-url points the window at `next dev` (hot reload) instead of the
36
- // built export; kept an argv flag so no cross-platform env helper is needed.
37
- const devUrlIndex = process.argv.indexOf('--dev-url');
38
- const DEV_URL = devUrlIndex >= 0 ? process.argv[devUrlIndex + 1] : null;
39
- const DEV_MODE = DEV_URL !== null;
40
- const log = (msg) => process.stderr.write(`[drone-path] ${msg}\n`);
41
-
42
- // Must run before app ready so the scheme gets standard/secure semantics.
43
- protocol.registerSchemesAsPrivileged([
44
- {
45
- scheme: SCHEME,
46
- privileges: { standard: true, secure: true, supportFetchAPI: true, stream: true },
47
- },
48
- ]);
49
-
50
- // Resolved against this script's directory (works in a checkout and in
51
- // app.asar); app.getAppPath() does not point at the repo root when Electron
52
- // is started with a script path.
53
- const exportRoot = uiExportRoot(import.meta.dirname);
54
-
55
- // The one window's mutable state, created in startup() and handed to every
56
- // stage as one object: the IPC handlers, the export runner callbacks and the
57
- // window lifecycle handlers share it, so each writer (export completion, the
58
- // close guard, window-all-closed) is a named handler instead of a nested
59
- // closure over scattered module globals.
60
- function createShellState() {
61
- return {
62
- win: null,
63
- session: null,
64
- config: null,
65
- appState: emptyAppState(),
66
- tileTraffic: null,
67
- // The one tile prefetch entry point every in-process lane drives.
68
- tilePrefetch: null,
69
- exportRunner: null,
70
- // The update controller, or null when this build cannot self-update.
71
- updates: null,
72
- // A downloaded update waits even if its announcement raced the renderer.
73
- updateReady: false,
74
- // The destinations of the last successful export and the last track
75
- // save: the only paths the renderer may reveal or open.
76
- lastExportOut: null,
77
- lastTrackOut: null,
78
- closePromptOpen: false,
79
- pendingClose: false,
80
- };
81
- }
82
-
83
- async function pickRecording(state) {
84
- const options = {
85
- title: 'Choose a drone recording',
86
- filters: [{ name: 'DJI recordings', extensions: ['mp4'] }],
87
- properties: ['openFile'],
88
- // Back where the last recording came from, when that folder still exists.
89
- defaultPath: rememberedOpenDir(state) ?? undefined,
90
- };
91
- const result = state.win
92
- ? await dialog.showOpenDialog(state.win, options)
93
- : await dialog.showOpenDialog(options);
94
- const picked = result.canceled ? null : result.filePaths[0];
95
- if (picked) rememberPicked(state, picked);
96
- return picked;
97
- }
98
-
99
- function rememberedOpenDir(state) {
100
- const dir = state.appState.lastOpenDir;
101
- return dir && fs.existsSync(dir) ? dir : undefined;
102
- }
103
-
104
- function rememberPicked(state, filePath) {
105
- state.appState = rememberOpenedFile(state.appState, filePath);
106
- try {
107
- writeAppState(appStateFile(), state.appState);
108
- } catch (e) {
109
- // The pick and the look still apply when the state file cannot be written.
110
- log(`app state not saved: ${errorMessage(e)}`);
111
- }
112
- }
113
-
114
- function fail(error) {
115
- const message = errorMessage(error);
116
- process.stderr.write(`${ERROR_PREFIX}${message}\n`);
117
- dialog.showErrorBox('Drone Path', message);
118
- app.quit();
119
- }
120
-
121
- function sendToWindow(state, channel, payload) {
122
- if (state.win && !state.win.isDestroyed()) state.win.webContents.send(channel, payload);
123
- }
124
-
125
- function handleExportDone(state, outcome) {
126
- if (outcome.status === 'ok') state.lastExportOut = outcome.summary.out;
127
- sendToWindow(state, 'dronepath:export:done', outcome);
128
- if (state.pendingClose) {
129
- state.pendingClose = false;
130
- if (state.win && !state.win.isDestroyed()) state.win.close();
131
- else app.quit();
132
- }
133
- }
134
-
135
- function videoResponse(request, filePath) {
136
- const size = fs.statSync(filePath).size;
137
- const plan = planByteRange(request.headers.get('range') ?? undefined, size, 'video/mp4');
138
- if (plan.status === 416) {
139
- return new Response(plan.body, { status: 416, headers: plan.headers });
140
- }
141
- const stream =
142
- plan.status === 206
143
- ? fs.createReadStream(filePath, { start: plan.span.start, end: plan.span.end })
144
- : fs.createReadStream(filePath);
145
- return new Response(Readable.toWeb(stream), { status: plan.status, headers: plan.headers });
146
- }
147
-
148
- // net.fetch only sets request headers; wrapping the body gives the client
149
- // the intended MIME and status.
150
- async function fileResponse(filePath, mime, status = 200) {
151
- const fetched = await net.fetch(pathToFileURL(filePath).toString());
152
- return new Response(fetched.body, { status, headers: { 'Content-Type': mime } });
153
- }
154
-
155
- function notFound() {
156
- const fallback = path.join(exportRoot, '404.html');
157
- return fs.existsSync(fallback)
158
- ? fileResponse(fallback, 'text/html; charset=utf-8', 404)
159
- : new Response('not found', { status: 404 });
160
- }
161
-
162
- async function handleRequest(state, request) {
163
- let pathname;
164
- try {
165
- pathname = decodeURIComponent(new URL(request.url).pathname);
166
- } catch {
167
- return new Response('bad request', { status: 400 });
168
- }
169
- const plan = resolveAppAsset(pathname, {
170
- exportRoot,
171
- tileCache: state.config.tileCache,
172
- videoPath: state.session ? state.session.videoPath() : null,
173
- });
174
- switch (plan.kind) {
175
- case 'video':
176
- return videoResponse(request, plan.filePath);
177
- case 'tile': {
178
- // Always through the tile traffic: it serves cached tiles immediately,
179
- // retries tiles whose earlier download failed (so they recover once
180
- // connectivity returns) and falls back to the placeholder.
181
- const file = await state.tileTraffic.ensure(plan.style, plan.tile);
182
- return fileResponse(file, 'image/png');
183
- }
184
- case 'export':
185
- if (fs.existsSync(plan.filePath)) return fileResponse(plan.filePath, plan.mime);
186
- return notFound();
187
- case 'not-found':
188
- return notFound();
189
- }
190
- }
191
-
192
- // The backing services behind the window: tool check, config, tile cache and
193
- // the recording session.
194
- async function initServices(state) {
195
- const resolved = resolveConfig({});
196
- state.appState = readAppState(appStateFile());
197
- state.config = applyAppState(resolved.config, state.appState);
198
- await requireFfmpegTools(resolveFfmpegTools(state.config));
199
- // One polite tile queue for the whole app: on-demand tiles and the export
200
- // prefetch share its request budget, and on-demand tiles the player needs
201
- // right now jump the queue.
202
- state.tileTraffic = createTileTraffic(state.config.tileCache);
203
- state.tilePrefetch = (options) => state.tileTraffic.stream(options);
204
- state.session = createAppSession({
205
- config: state.config,
206
- pickFile: () => pickRecording(state),
207
- log,
208
- onPreparing: () => sendToWindow(state, 'dronepath:preparing'),
209
- onPrepareProgress: (progress) =>
210
- sendToWindow(state, 'dronepath:preparing:progress', progress),
211
- });
212
- }
213
-
214
- function initExportRunner(state) {
215
- state.exportRunner = createExportRunner({
216
- log: (msg) => {
217
- log(msg);
218
- sendToWindow(state, 'dronepath:export:progress', msg);
219
- },
220
- onCapture: (progress) =>
221
- sendToWindow(state, 'dronepath:export:capture', progress),
222
- onDone: (outcome) => handleExportDone(state, outcome),
223
- // An export warms tiles next to the live app: same queue, same budget.
224
- deps: { prefetchTiles: state.tilePrefetch },
225
- });
226
- }
227
-
228
- function installProtocolHandler(state) {
229
- protocol.handle(SCHEME, (request) =>
230
- handleRequest(state, request).catch((e) => {
231
- log(`scheme error: ${errorMessage(e)}`);
232
- return new Response('internal error', { status: 500 });
233
- }),
234
- );
235
- }
236
-
237
- function ensureUiExport() {
238
- if (!DEV_MODE && !fs.existsSync(path.join(exportRoot, 'index.html'))) {
239
- throw new Error('ui export missing; run "npm run build" first');
240
- }
241
- }
242
-
243
- function createWindow(state) {
244
- // The in-app menu bar owns all workspace commands; a native Alt/F10 menu
245
- // would compete with it, so none is installed (Windows and Linux).
246
- Menu.setApplicationMenu(null);
247
- state.win = new BrowserWindow({
248
- width: 1600,
249
- height: 950,
250
- // The control bar needs ~1000px of min-content width; below this the
251
- // right-hand buttons would become unreachable.
252
- minWidth: 1024,
253
- minHeight: 600,
254
- // Match --page in ui/app/globals.css so startup shows one background.
255
- backgroundColor: '#232323',
256
- // The loaded page's <title> takes over after load (ui/app/layout.tsx).
257
- title: 'Drone Path',
258
- // Windows renders an ICO best, Linux a PNG (Electron docs); both are
259
- // derived from build/icon-master.png (see build/README.md).
260
- icon:
261
- process.platform === 'win32'
262
- ? path.join(import.meta.dirname, '..', 'build', 'icon.ico')
263
- : path.join(import.meta.dirname, '..', 'build', 'icons', '256x256.png'),
264
- webPreferences: {
265
- preload: path.join(import.meta.dirname, 'preload.cjs'),
266
- contextIsolation: true,
267
- sandbox: true,
268
- nodeIntegration: false,
269
- },
270
- });
271
- state.win.on('closed', () => {
272
- state.win = null;
273
- });
274
- // Web links (e.g. in the user manual) open in the system browser, never in
275
- // a second app window.
276
- state.win.webContents.setWindowOpenHandler(({ url }) => {
277
- if (/^(https?|mailto):/i.test(url)) void shell.openExternal(url);
278
- return { action: 'deny' };
279
- });
280
- }
281
-
282
- // Closing the window must not silently kill a running export and strand
283
- // minutes of work; the user chooses between stopping and keeping it.
284
- function installCloseGuard(state) {
285
- state.win.on('close', (e) => {
286
- // A close already confirmed by the user, or with nothing running, passes.
287
- if (state.pendingClose || !state.exportRunner || !state.exportRunner.running()) return;
288
- if (state.closePromptOpen) {
289
- e.preventDefault();
290
- return;
291
- }
292
- e.preventDefault();
293
- state.closePromptOpen = true;
294
- const box = {
295
- type: 'warning',
296
- buttons: ['Stop Export and Close', 'Keep Exporting'],
297
- defaultId: 1,
298
- cancelId: 1,
299
- message: 'An export is in progress',
300
- detail: 'Closing the window stops the export and removes its unfinished file.',
301
- };
302
- void (state.win ? dialog.showMessageBox(state.win, box) : dialog.showMessageBox(box)).then(
303
- ({ response }) => {
304
- state.closePromptOpen = false;
305
- if (response !== 0) return;
306
- // Cancellation settles asynchronously: the close completes from the
307
- // job's onDone, never from a synchronous running() check.
308
- state.pendingClose = true;
309
- state.exportRunner.cancel();
310
- },
311
- );
312
- });
313
- }
314
-
315
- async function loadUi(state) {
316
- await state.win.loadURL(DEV_MODE ? DEV_URL : `${APP_ORIGIN}/`);
317
- }
318
-
319
- // The window is the app: closing it quits. A still-running export delays the
320
- // quit until its job has settled and cleaned up after itself.
321
- function handleWindowAllClosed(state) {
322
- if (state.exportRunner && state.exportRunner.running()) {
323
- state.pendingClose = true;
324
- state.exportRunner.cancel();
325
- return;
326
- }
327
- app.quit();
328
- }
329
-
330
- async function startup() {
331
- const state = createShellState();
332
- app.on('window-all-closed', () => handleWindowAllClosed(state));
333
- try {
334
- await initServices(state);
335
- initExportRunner(state);
336
- state.updates = initUpdates({
337
- log,
338
- onReady: () => {
339
- // Buffered: the cache fast path can announce before the renderer
340
- // subscribes, and the state handler replays it on mount.
341
- state.updateReady = true;
342
- sendToWindow(state, 'dronepath:update:ready');
343
- },
344
- });
345
- registerIpcHandlers(state, { devUrl: DEV_URL, log, sendToWindow });
346
- installProtocolHandler(state);
347
- ensureUiExport();
348
- createWindow(state);
349
- installCloseGuard(state);
350
- await loadUi(state);
351
- } catch (e) {
352
- fail(e);
353
- }
354
- }
355
-
356
- app.whenReady().then(startup);
package/app/preload.cjs DELETED
@@ -1,34 +0,0 @@
1
- // Preload bridge for the UI: the only surface the renderer sees. CommonJS
2
- // (.cjs) because sandboxed preload scripts cannot use ESM.
3
- const { contextBridge, ipcRenderer } = require('electron');
4
-
5
- function subscribe(channel, adapt) {
6
- const handler = (_event, payload) => adapt(payload);
7
- ipcRenderer.on(channel, handler);
8
- return () => ipcRenderer.removeListener(channel, handler);
9
- }
10
-
11
- contextBridge.exposeInMainWorld('dronepath', {
12
- pickRecording: (request) => ipcRenderer.invoke('dronepath:pick', request),
13
- getSession: () => ipcRenderer.invoke('dronepath:session'),
14
- getSettings: () => ipcRenderer.invoke('dronepath:settings'),
15
- saveSettings: (patch) => ipcRenderer.invoke('dronepath:settings:save', patch),
16
- pickExportOutput: () => ipcRenderer.invoke('dronepath:export:pick-output'),
17
- pickTrackOutput: () => ipcRenderer.invoke('dronepath:track:pick-output'),
18
- saveTrack: (request) => ipcRenderer.invoke('dronepath:track:save', request),
19
- startExport: (request) => ipcRenderer.invoke('dronepath:export:start', request),
20
- cancelExport: () => ipcRenderer.invoke('dronepath:export:cancel'),
21
- revealExportOutput: (payload) => ipcRenderer.invoke('dronepath:export:reveal', payload),
22
- openExportOutput: (payload) => ipcRenderer.invoke('dronepath:export:open', payload),
23
- onExportProgress: (cb) => subscribe('dronepath:export:progress', cb),
24
- onExportCapture: (cb) => subscribe('dronepath:export:capture', cb),
25
- onExportDone: (cb) => subscribe('dronepath:export:done', cb),
26
- onPreparing: (cb) => subscribe('dronepath:preparing', () => cb()),
27
- onPrepareProgress: (cb) => subscribe('dronepath:preparing:progress', cb),
28
- onUpdateReady: (cb) => subscribe('dronepath:update:ready', () => cb()),
29
- onUpdateRestartFailed: (cb) =>
30
- subscribe('dronepath:update:restart-failed', (message) => cb(message)),
31
- getUpdateState: () => ipcRenderer.invoke('dronepath:update:state'),
32
- restartToUpdate: () => ipcRenderer.invoke('dronepath:update:restart'),
33
- closeWindow: () => ipcRenderer.invoke('dronepath:window:close'),
34
- });
@@ -1,6 +0,0 @@
1
- export interface UpdateGateInput {
2
- packaged: boolean;
3
- hasUpdateMetadata: boolean;
4
- }
5
-
6
- export declare function shouldCheckForUpdates(input: UpdateGateInput): boolean;
@@ -1,6 +0,0 @@
1
- // Whether this install can ever self-update. Only packaged builds that carry
2
- // electron-builder's update metadata talk to the feed: NSIS and AppImage
3
- // builds ship app-update.yml, portable installs and dev runs never do.
4
- export function shouldCheckForUpdates({ packaged, hasUpdateMetadata }) {
5
- return packaged && hasUpdateMetadata;
6
- }
package/app/update.d.mts DELETED
@@ -1,10 +0,0 @@
1
- export interface UpdateController {
2
- restart(deps: { onError: (message: string) => void }): { ok: true } | { ok: false; error: string };
3
- }
4
-
5
- export interface InitUpdatesOptions {
6
- log: (message: string) => void;
7
- onReady: () => void;
8
- }
9
-
10
- export function initUpdates(options: InitUpdatesOptions): UpdateController | null;
package/app/update.mjs DELETED
@@ -1,54 +0,0 @@
1
- // Auto-update for the packaged desktop app: check the GitHub release feed,
2
- // download in the background and let the UI prompt before the restart. Every
3
- // failure stays a stderr line and never touches startup.
4
- import fs from 'node:fs';
5
- import path from 'node:path';
6
- import process from 'node:process';
7
-
8
- import { app } from 'electron';
9
- // The default import then destructuring keeps ESM consumers off the CJS named
10
- // export interop (electron-builder issue #7976).
11
- import electronUpdater from 'electron-updater';
12
-
13
- import { errorMessage } from '../dist/errors.js';
14
- import { shouldCheckForUpdates } from './update-policy.mjs';
15
-
16
- const { autoUpdater } = electronUpdater;
17
-
18
- export function initUpdates({ log, onReady }) {
19
- const hasUpdateMetadata = fs.existsSync(path.join(process.resourcesPath, 'app-update.yml'));
20
- if (!shouldCheckForUpdates({ packaged: app.isPackaged, hasUpdateMetadata })) return null;
21
-
22
- autoUpdater.autoDownload = true;
23
- // A postponed prompt must still install the update on the next regular quit.
24
- autoUpdater.autoInstallOnAppQuit = true;
25
- autoUpdater.logger = {
26
- info: (message) => log(`update: ${message}`),
27
- warn: (message) => log(`update: ${message}`),
28
- error: (message) => log(`update: ${message}`),
29
- };
30
- // Feed and download failures are background noise: report and continue.
31
- autoUpdater.on('error', (e) => log(`update failed: ${errorMessage(e)}`));
32
- autoUpdater.on('update-downloaded', () => onReady());
33
- autoUpdater.checkForUpdates().catch((e) => log(`update check failed: ${errorMessage(e)}`));
34
-
35
- return {
36
- // electron-updater swallows install failures onto its 'error' event and
37
- // keeps running: both the thrown and the emitted failure must surface or
38
- // the restart prompt would wait forever.
39
- restart({ onError }) {
40
- const fail = (e) => {
41
- autoUpdater.removeListener('error', fail);
42
- onError(errorMessage(e));
43
- };
44
- autoUpdater.once('error', fail);
45
- try {
46
- autoUpdater.quitAndInstall(true, true);
47
- } catch (e) {
48
- fail(e);
49
- return { ok: false, error: errorMessage(e) };
50
- }
51
- return { ok: true };
52
- },
53
- };
54
- }
package/dist/appassets.js DELETED
@@ -1,35 +0,0 @@
1
- import path from 'node:path';
2
- import { mimeFor, resolveTileRoute } from './assets.js';
3
- import { MEDIA_PATH } from './apppaths.js';
4
- export function resolveAppAsset(pathname, routes) {
5
- if (pathname === MEDIA_PATH) {
6
- return routes.videoPath
7
- ? { kind: 'video', filePath: routes.videoPath }
8
- : { kind: 'not-found' };
9
- }
10
- const tile = resolveTileRoute(pathname, routes.tileCache, { anyStyle: true });
11
- if (tile) {
12
- return { kind: 'tile', ...tile };
13
- }
14
- return exportFile(pathname, routes.exportRoot);
15
- }
16
- function exportFile(pathname, exportRoot) {
17
- let rel = pathname.replace(/^\/+/, '');
18
- if (rel === '' || rel.endsWith('/'))
19
- rel += 'index.html';
20
- // Windows drive prefixes or backslashes would be a plain file name to POSIX
21
- // resolution; refuse them so the guard works the same on every OS.
22
- if (rel.split('/').some((s) => s.includes('\\') || /^[a-zA-Z]:/.test(s))) {
23
- return { kind: 'not-found' };
24
- }
25
- const filePath = path.resolve(exportRoot, rel);
26
- const relCheck = path.relative(exportRoot, filePath);
27
- if (relCheck === '' || relCheck.startsWith('..') || path.isAbsolute(relCheck)) {
28
- return { kind: 'not-found' };
29
- }
30
- return {
31
- kind: 'export',
32
- filePath,
33
- mime: mimeFor(filePath),
34
- };
35
- }
package/dist/apppaths.js DELETED
@@ -1,20 +0,0 @@
1
- import os from 'node:os';
2
- import path from 'node:path';
3
- export const APP_ORIGIN = 'app://bundle';
4
- export const MEDIA_PATH = '/media/video';
5
- const MEDIA_URL = APP_ORIGIN + MEDIA_PATH;
6
- export const TILE_BASE = APP_ORIGIN + '/tiles';
7
- // The ?v= query names the file so a reload can never replay another recording's bytes from a URL-keyed cache.
8
- export function mediaUrlFor(videoPath) {
9
- return `${MEDIA_URL}?v=${encodeURIComponent(videoPath)}`;
10
- }
11
- export function uiExportRoot(shellDir) {
12
- return path.join(shellDir, '..', 'ui', 'out');
13
- }
14
- export function userDataDir() {
15
- const base = process.env['LOCALAPPDATA'] ?? path.join(os.homedir(), '.cache');
16
- return path.join(base, 'drone-path');
17
- }
18
- export function appStateFile() {
19
- return path.join(userDataDir(), 'state.json');
20
- }
@@ -1,121 +0,0 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import { z } from 'zod';
4
- import { TILE_BASE, mediaUrlFor } from './apppaths.js';
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';
13
- export function frameExactDuration(probe) {
14
- return timeAt(probe.frames, probe.fps.value);
15
- }
16
- export function parsePickRequest(raw) {
17
- const input = typeof raw === 'object' && raw !== null ? raw : {};
18
- return { settings: parseAppearanceSettings(input.settings) };
19
- }
20
- const TRACK_SAVE_SHAPE = {
21
- outPath: z.unknown().optional(),
22
- range: z.unknown().optional(),
23
- };
24
- export function parseTrackSaveRequest(raw) {
25
- const request = parseValue(strictShape(TRACK_SAVE_SHAPE, {
26
- invalid: 'invalid track save request',
27
- unknownKey: (key) => `unknown track save request key ${key}`,
28
- }), raw);
29
- const outPath = parseValue(z
30
- .string({ error: () => 'invalid track save request: outPath' })
31
- .min(1, { error: () => 'invalid track save request: outPath' }), request.outPath);
32
- try {
33
- trackFormatOf(outPath);
34
- }
35
- catch (e) {
36
- throw new Error(`invalid track save request: outPath must be a .gpx, .geojson, .kml, .kmz or .json file: ${outPath}`, { cause: e });
37
- }
38
- const range = request.range === undefined || request.range === null
39
- ? null
40
- : parseFrameRange(request.range);
41
- return { outPath, range };
42
- }
43
- export const prepareUiSession = async (videoPath, config, log, onProgress, deps) => {
44
- const prep = await prepareSession(videoPath, config, log, {
45
- onProgress,
46
- deps,
47
- });
48
- return {
49
- session: {
50
- scene: buildSceneData(recordingPageOpts(prep, config), TILE_BASE),
51
- video: {
52
- src: mediaUrlFor(videoPath),
53
- fps: prep.probe.fps.value,
54
- frames: prep.probe.frames,
55
- width: prep.probe.width,
56
- height: prep.probe.height,
57
- },
58
- tileBase: TILE_BASE,
59
- bbox: prep.tel.bbox,
60
- durationSec: frameExactDuration(prep.probe),
61
- },
62
- telemetry: telemetryExportInput(prep),
63
- track: trackExportStream(prep),
64
- };
65
- };
66
- function isReadableVideo(filePath) {
67
- if (!isRecordingName(filePath))
68
- return false;
69
- try {
70
- return fs.statSync(filePath).isFile();
71
- }
72
- catch {
73
- return false;
74
- }
75
- }
76
- export function createAppSession(options) {
77
- const { config, pickFile } = options;
78
- const prepare = options.prepare ?? prepareUiSession;
79
- const log = options.log ?? (() => { });
80
- const onPreparing = options.onPreparing ?? (() => { });
81
- const onPrepareProgress = options.onPrepareProgress ?? (() => { });
82
- let prepared = null;
83
- let videoPath = null;
84
- let picking = false;
85
- return {
86
- async pick(request) {
87
- if (picking)
88
- return { ok: false, error: 'a pick is already in progress' };
89
- picking = true;
90
- try {
91
- const picked = await pickFile();
92
- if (picked === null)
93
- return { ok: false, canceled: true };
94
- const resolved = path.resolve(picked);
95
- if (!isReadableVideo(resolved)) {
96
- log(`rejected: ${resolved}`);
97
- return { ok: false, error: `${ERR_NOT_READABLE_MP4}${resolved}` };
98
- }
99
- onPreparing(resolved);
100
- prepared = await prepare(resolved, { ...config, ...request.settings }, log, onPrepareProgress);
101
- videoPath = resolved;
102
- log(`loaded: ${resolved}`);
103
- return { ok: true };
104
- }
105
- catch (e) {
106
- log(`error: ${errorMessage(e)}`);
107
- return { ok: false, error: errorMessage(e) };
108
- }
109
- finally {
110
- picking = false;
111
- }
112
- },
113
- getSession: () => prepared?.session ?? null,
114
- videoPath: () => videoPath,
115
- saveTrack(file, range) {
116
- if (!prepared)
117
- throw new Error(ERR_NO_RECORDING);
118
- writeTrackFile(file, { document: prepared.telemetry, track: prepared.track }, range);
119
- },
120
- };
121
- }