Files
openscreen/src/lib/recordingSession.ts
T
2026-03-17 19:09:34 +08:00

70 lines
1.5 KiB
TypeScript

export interface ProjectMedia {
screenVideoPath: string;
webcamVideoPath?: string;
}
export interface RecordingSession extends ProjectMedia {
createdAt: number;
}
export interface RecordedVideoAssetInput {
fileName: string;
videoData: ArrayBuffer;
}
export interface StoreRecordedSessionInput {
screen: RecordedVideoAssetInput;
webcam?: RecordedVideoAssetInput;
createdAt?: number;
}
function normalizePath(value: unknown): string | undefined {
if (typeof value !== "string") {
return undefined;
}
const trimmed = value.trim();
return trimmed ? trimmed : undefined;
}
export function normalizeProjectMedia(candidate: unknown): ProjectMedia | null {
if (!candidate || typeof candidate !== "object") {
return null;
}
const raw = candidate as Partial<ProjectMedia>;
const screenVideoPath = normalizePath(raw.screenVideoPath);
if (!screenVideoPath) {
return null;
}
const webcamVideoPath = normalizePath(raw.webcamVideoPath);
return webcamVideoPath
? { screenVideoPath, webcamVideoPath }
: {
screenVideoPath,
};
}
export function normalizeRecordingSession(candidate: unknown): RecordingSession | null {
if (!candidate || typeof candidate !== "object") {
return null;
}
const raw = candidate as Partial<RecordingSession>;
const media = normalizeProjectMedia(raw);
if (!media) {
return null;
}
return {
...media,
createdAt:
typeof raw.createdAt === "number" && Number.isFinite(raw.createdAt)
? raw.createdAt
: Date.now(),
};
}