import catalog from "@/runtime/nianxx-play/content/seedance-starter/catalog.json"; type LegacyCatalog = typeof catalog; type LegacyCase = LegacyCatalog["cases"][number]; export type VideoTemplate = { id: string; title: string; mode: string; modeLabel: string; prompt: string; seedanceInstruction?: string; coverUrl?: string; referenceVideoUrl?: string; resultVideoUrl?: string; selectable: boolean; controls: string[]; materials: Array<{ role: string; type: "image" | "video" | "audio"; url: string; label?: string; }>; }; export function getVideoTemplates(): VideoTemplate[] { return (catalog.cases as LegacyCase[]).map((item) => ({ id: item.id, title: item.title, mode: item.mode, modeLabel: item.modeLabel, prompt: item.prompt, seedanceInstruction: typeof item.promptPattern?.seedanceInstruction === "string" ? item.promptPattern.seedanceInstruction : undefined, coverUrl: rewriteLegacyUrl(item.display?.coverPublicUrl), referenceVideoUrl: rewriteLegacyUrl(item.display?.referenceVideoPublicUrl), resultVideoUrl: rewriteLegacyUrl(item.display?.resultVideoPublicUrl), selectable: Boolean(item.display?.selectableAsReferenceTemplate), controls: item.interactionHooks?.visibleControls || [], materials: (item.assets || []) .map((asset) => ({ role: asset.role, type: asset.role.includes("video") ? "video" as const : asset.role.includes("audio") ? "audio" as const : "image" as const, url: rewriteLegacyUrl(asset.publicUrl) || "", label: "promptLabel" in asset ? asset.promptLabel : undefined })) .filter((asset) => asset.url) })); } export function getTemplateById(id?: string): VideoTemplate | undefined { if (!id) return undefined; return getVideoTemplates().find((template) => template.id === id); } function rewriteLegacyUrl(url?: string | null): string | undefined { if (!url) return undefined; if (/^https?:\/\//i.test(url)) return url; if (url.startsWith("/seedance-starter-assets/") || url.startsWith("/starter/") || url.startsWith("/planning-cases/")) return url; return url; }