export type VideoArchiveMetadata = Record & { storageStatus: "archived" | "temporary"; temporaryVideoUrl: string; permanentVideoUrl?: string; }; export async function preserveGeneratedVideo( sourceUrl: string, metadata: Record | null | undefined, archive: (url: string) => Promise, ): 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 } }; } }