ai-chatbot/lib/video-canvas/archive-result.ts

20 lines
822 B
TypeScript

export type VideoArchiveMetadata = Record<string, unknown> & {
storageStatus: "archived" | "temporary";
temporaryVideoUrl: string;
permanentVideoUrl?: string;
};
export async function preserveGeneratedVideo(
sourceUrl: string,
metadata: Record<string, unknown> | null | undefined,
archive: (url: string) => Promise<string>,
): Promise<{ url: string; metadata: VideoArchiveMetadata }> {
try {
const url = await archive(sourceUrl);
if (!url || url === sourceUrl) throw new Error("No permanent copy created");
return { url, metadata: { ...metadata, storageStatus: "archived", temporaryVideoUrl: sourceUrl, permanentVideoUrl: url } };
} catch {
return { url: sourceUrl, metadata: { ...metadata, storageStatus: "temporary", temporaryVideoUrl: sourceUrl, permanentVideoUrl: undefined } };
}
}