fix(canvas): 画布媒体 - 修复预览首帧音量和创作状态展示

This commit is contained in:
Codex Audit committed 2026-09-23 11:10:45 +08:00
1 parent 7737047a8d
commit 12796b048c
30 files changed
+689 -182

No files matched your search

+26 -7
View File
@@ -1,19 +1,38 @@
import { buildLibTVVideoPreviewUrl } from "@/lib/canvas/libtv-import";
import { CanvasNodeType, type CanvasNodeData } from "@/types/canvas";
export type CanvasVideoPreviewReference = {
src: string;
storageKey?: string;
};
/**
* Returns the passive preview image reference for a video node.
*
* `storageKey` is kept separate from the fallback URL so UI callers can
* resolve a fresh OSS/CDN display URL instead of mounting a stale historical
* `/api/resources/:id/file` URL stored in older canvas data.
*/
export function canvasNodeVideoPreviewReference(node: CanvasNodeData): CanvasVideoPreviewReference | null {
if (node.type !== CanvasNodeType.Video) return null;
const content = node.metadata?.content || "";
const generatedPreview = node.metadata?.videoPreview;
if (generatedPreview?.storageKey || (generatedPreview?.content && generatedPreview.content !== content)) {
return { src: generatedPreview.content || "", storageKey: generatedPreview.storageKey };
}
const explicitPreview = node.metadata?.previewContent || "";
if (explicitPreview && explicitPreview !== content) return { src: explicitPreview };
const importedPreview = buildLibTVVideoPreviewUrl(content);
return importedPreview ? { src: importedPreview } : null;
}
/**
* Returns an image source that is safe to mount for a passive video preview.
* The original video URL is deliberately never returned: callers must fall
* back to a video icon instead of creating a decoder outside the active node.
*/
export function canvasNodeVideoPreviewUrl(node: CanvasNodeData) {
if (node.type !== CanvasNodeType.Video) return "";
const content = node.metadata?.content || "";
const generatedPreview = node.metadata?.videoPreview?.content || "";
if (generatedPreview && generatedPreview !== content) return generatedPreview;
const explicitPreview = node.metadata?.previewContent || "";
if (explicitPreview && explicitPreview !== content) return explicitPreview;
return buildLibTVVideoPreviewUrl(content);
return canvasNodeVideoPreviewReference(node)?.src || "";
}
export function canvasVideoAssetPreviewUrl(videoUrl: string, coverUrl?: string) {