fix(canvas): 远程媒体 - 统一资源地址并校验视频缓存

This commit is contained in:
ddCat
2026-09-19 22:29:09 +08:00
parent 14a78c3c18
commit db9e18da1e
10 changed files with 83 additions and 134 deletions

View File

@@ -12,6 +12,7 @@ import { uploadGeneratedAssetToConfiguredSources } from "@/services/external-ass
import { getImageBlob, resolveImageUrl, setImageBlob } from "@/services/image-storage";
import { generationArtifactStorageKey, loadOrStoreGenerationArtifact } from "@/services/generation-artifact-sink";
import { createProviderNeutralGenerationTaskEffectStore } from "@/services/provider-neutral-generation-effects";
import { getCachedResourceBlob } from "@/services/resource-blob-cache";
import { saveRemoteUserDataNow } from "@/services/user-data-sync";
import { getActiveUserScope } from "@/lib/user-scope";
import { normalizeAssetCategory } from "@/lib/asset-category";
@@ -265,6 +266,26 @@ async function storedGenerationMedia(dataUrl: string, effectKey: string, mediaTy
};
}
async function cachedRemoteGenerationVideo(video: NonNullable<BackendGenerationResult["video"]>, signal?: AbortSignal) {
if (!video.storageKey) throw new Error("生成视频缺少云端资源标识");
throwIfAborted(signal);
const blob = await getCachedResourceBlob(video.storageKey);
throwIfAborted(signal);
if (!blob) throw new Error("生成视频资源缓存失败,未标记为成功");
const url = await resolveMediaUrl(video.storageKey, video.dataUrl);
throwIfAborted(signal);
if (!url) throw new Error("生成视频资源地址为空,未标记为成功");
return {
url,
storageKey: video.storageKey,
width: video.width || 0,
height: video.height || 0,
durationMs: video.durationMs,
bytes: video.bytes || blob.size,
mimeType: video.mimeType || blob.type || "video/mp4",
};
}
async function generationOutputAsset(input: Parameters<MaterializeGenerationTaskOutput>[0], scope: string): Promise<NewAsset> {
throwIfAborted(input.signal);
const result = generationTaskResult(input.task);
@@ -305,15 +326,7 @@ async function generationOutputAsset(input: Parameters<MaterializeGenerationTask
const video = result.video;
if (!video) throw new Error("生成任务缺少视频输出");
const stored = video.storageKey
? {
url: await resolveMediaUrl(video.storageKey, video.dataUrl),
storageKey: video.storageKey,
width: video.width || 0,
height: video.height || 0,
durationMs: video.durationMs,
bytes: video.bytes || 0,
mimeType: video.mimeType || "video/mp4",
}
? await cachedRemoteGenerationVideo(video, input.signal)
: await storedGenerationMedia(
video.dataUrl,
input.effectKey,