mirror of
https://github.com/nexu-io/openmotion.git
synced 2026-12-01 23:51:42 +08:00
32 lines
1.9 KiB
TypeScript
32 lines
1.9 KiB
TypeScript
export type NativeStage = 'idle' | 'waiting' | 'downloading' | 'verifying' | 'extracting' | 'checking' | 'ready' | 'failed';
|
|
export type NativeComponent = {
|
|
id: 'browser' | 'media' | 'ffmpeg' | 'ffprobe';
|
|
stage: NativeStage;
|
|
receivedBytes?: number;
|
|
totalBytes?: number;
|
|
downloadStartedAt?: number;
|
|
updatedAt?: number;
|
|
attempt?: number;
|
|
maxAttempts?: number;
|
|
errorCode?: string;
|
|
error?: string;
|
|
};
|
|
export type NativeRuntimeStatus = { managed: boolean; components: NativeComponent[]; capabilities: { capture: boolean; media: boolean; export: boolean } };
|
|
|
|
export function parseNativeRuntimeStatus(value: unknown): NativeRuntimeStatus | null {
|
|
const status = value as NativeRuntimeStatus | null;
|
|
if (!status || typeof status.managed !== 'boolean' || !Array.isArray(status.components) || !status.capabilities
|
|
|| !['capture', 'media', 'export'].every(key => typeof (status.capabilities as any)[key] === 'boolean')
|
|
|| !status.components.every(component => component && ['browser', 'media', 'ffmpeg', 'ffprobe'].includes(component.id)
|
|
&& ['idle', 'waiting', 'downloading', 'verifying', 'extracting', 'checking', 'ready', 'failed'].includes(component.stage)
|
|
&& [component.receivedBytes, component.totalBytes, component.downloadStartedAt, component.updatedAt, component.attempt, component.maxAttempts].every(bytes => bytes === undefined || Number.isFinite(bytes) && bytes >= 0)
|
|
&& (component.error === undefined || typeof component.error === 'string'))) return null;
|
|
return status;
|
|
}
|
|
|
|
export function nativeRouteCapability(method: string, pathname: string): 'capture' | 'media' | 'export' | undefined {
|
|
if (method === 'POST' && /^\/api\/projects\/[^/]+\/render$/.test(pathname)) return 'export';
|
|
if (method === 'GET' && /^\/api\/projects\/[^/]+\/thumbnail\//.test(pathname)) return 'capture';
|
|
if (/^\/api\/projects\/[^/]+\/(?:upload|waveform\/|peaks\/|media\/|loudness\/normalize|file-mutations\/freeze-frame)/.test(pathname)) return 'media';
|
|
}
|