fix(canvas): 任务结果恢复 - 规范化分镜行文本字段

This commit is contained in:
root
2026-09-21 20:13:22 +08:00
parent 72c0a037de
commit 64832b2fb5
2 changed files with 60 additions and 5 deletions

View File

@@ -150,6 +150,42 @@ function parseStoryboardRowsPayload(raw: string): { title?: string; rows?: Array
return parsed;
}
function normalizeStoryboardText(value: unknown): string {
if (typeof value === "string") return value;
if (typeof value === "number" || typeof value === "boolean") return String(value);
if (Array.isArray(value)) return value.map(normalizeStoryboardText).filter(Boolean).join("、");
if (!value || typeof value !== "object") return "";
const record = value as Record<string, unknown>;
for (const key of ["text", "content", "value", "description", "name"]) {
if (!(key in record)) continue;
const nested = normalizeStoryboardText(record[key]);
if (nested) return nested;
}
return "";
}
function normalizeStoryboardRow(row: Partial<StoryboardRow>): Partial<StoryboardRow> {
return {
...row,
plotDescription: normalizeStoryboardText(row.plotDescription),
dialogue: normalizeStoryboardText(row.dialogue),
narrativeIntent: normalizeStoryboardText(row.narrativeIntent),
viewerPOV: normalizeStoryboardText(row.viewerPOV),
performanceBlocking: normalizeStoryboardText(row.performanceBlocking),
shotSize: normalizeStoryboardText(row.shotSize),
emotion: normalizeStoryboardText(row.emotion),
lightingAndAtmosphere: normalizeStoryboardText(row.lightingAndAtmosphere),
audioEffects: normalizeStoryboardText(row.audioEffects),
camera: normalizeStoryboardText(row.camera),
motion: normalizeStoryboardText(row.motion),
timeBeats: normalizeStoryboardText(row.timeBeats),
imageGenerationPrompt: normalizeStoryboardText(row.imageGenerationPrompt),
videoMotionPrompt: normalizeStoryboardText(row.videoMotionPrompt),
continuityOut: normalizeStoryboardText(row.continuityOut),
negativePrompt: normalizeStoryboardText(row.negativePrompt),
};
}
export function storyboardRowsFromTask(task: GenerationTask) {
const result = parseStoryboardRowsPayload(task.resultJson || "{}");
if (!Array.isArray(result.rows) || !result.rows.length) throw new Error("分镜任务没有返回镜头行");
@@ -158,16 +194,17 @@ export function storyboardRowsFromTask(task: GenerationTask) {
// 否则可选链只能防 undefined,仍会在对象上调用 trim 使整页恢复失败。
title: typeof result.title === "string" ? result.title.trim() : undefined,
rows: result.rows.map((row, index) => {
const source = row && typeof row === "object" ? row : {};
const next = createStoryboardRow(index + 1, {
...row,
...normalizeStoryboardRow(source),
id: `shot-${Date.now()}-${index + 1}-${Math.random().toString(36).slice(2, 6)}`,
shotNumber: index + 1,
status: "idle",
assetBindings: normalizeStoryboardAssetBindings(row.assetBindings),
assetBindings: normalizeStoryboardAssetBindings(Array.isArray(source.assetBindings) ? source.assetBindings : undefined),
});
next.characters = Array.isArray(row.characters) ? row.characters : [];
next.mustHave = Array.isArray(row.mustHave) ? row.mustHave : [];
next.optionalDetails = Array.isArray(row.optionalDetails) ? row.optionalDetails : [];
next.characters = Array.isArray(source.characters) ? source.characters : [];
next.mustHave = Array.isArray(source.mustHave) ? source.mustHave : [];
next.optionalDetails = Array.isArray(source.optionalDetails) ? source.optionalDetails : [];
return next;
}),
};