fix(canvas): 生成结果命名 - 保留复制与参数变体标识避免下载重名
This commit is contained in:
23
web/src/lib/canvas/canvas-generation-title.ts
Normal file
23
web/src/lib/canvas/canvas-generation-title.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import type { CanvasNodeData } from "@/types/canvas";
|
||||
|
||||
const COPY_SUFFIX = /(_copy\d+|\s+Copy)$/i;
|
||||
const VERSION_SUFFIX = /\s*·\s*([A-Z])\s*$/;
|
||||
|
||||
export function buildImageGenerationNodeTitle(prompt: string, sourceNode?: CanvasNodeData, outputIndex?: number, outputCount = 1) {
|
||||
let title = prompt.trim().slice(0, 32) || "Generated Image";
|
||||
if (sourceNode) {
|
||||
const sourceTitleWithoutVersion = sourceNode.title.replace(VERSION_SUFFIX, "");
|
||||
const copySuffix = sourceTitleWithoutVersion.match(COPY_SUFFIX)?.[1] || "";
|
||||
const versionLabel = validVersionLabel(sourceNode.metadata?.versionLabel) || sourceNode.title.match(VERSION_SUFFIX)?.[1] || "";
|
||||
const titleWithoutVersion = title.replace(VERSION_SUFFIX, "");
|
||||
if (copySuffix && !titleWithoutVersion.toLowerCase().endsWith(copySuffix.toLowerCase())) title += copySuffix;
|
||||
if (versionLabel && !title.endsWith(` · ${versionLabel}`)) title += ` · ${versionLabel}`;
|
||||
}
|
||||
if (outputCount > 1 && outputIndex !== undefined) title += ` · ${outputIndex + 1}`;
|
||||
return title;
|
||||
}
|
||||
|
||||
function validVersionLabel(value?: string) {
|
||||
const normalized = value?.trim().toUpperCase() || "";
|
||||
return /^[A-Z]$/.test(normalized) ? normalized : "";
|
||||
}
|
||||
Reference in New Issue
Block a user