feat(canvas): 画布工作台 - 新增生成副本并修复大型画布性能、素材同步与删除校验
统一图片与视频副本的生成落点并保留参考连接。\n优化大型画布节点虚拟化、媒体懒加载、拖拽与详情进入路径。\n修复素材主版本 ID 同步及删除时的画布独立引用校验。
This commit is contained in:
1 parent
434f63e153
commit
3f4a9ea3d0
45 files changed
+1348
-286
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { nanoid } from "nanoid";
|
||||
|
||||
import { NODE_DEFAULT_SIZE } from "@/constant/canvas";
|
||||
import { canGenerateMediaInPlace } from "@/lib/canvas/canvas-generation-layout";
|
||||
import { nodeSizeFromRatio } from "@/lib/canvas/canvas-node-size";
|
||||
import { nextCanvasVersionLabel } from "@/lib/canvas/canvas-layout";
|
||||
import { buildAudioGenerationMetadata, buildVideoGenerationMetadata, generationReferenceUrls, runCanvasGenerationTaskToConsumer } from "@/lib/canvas/canvas-project-generation";
|
||||
@@ -33,9 +34,9 @@ export async function executeVideoGeneration({
|
||||
retryContext,
|
||||
}: CanvasGenerationExecution) {
|
||||
const spec = nodeSizeFromRatio(generationConfig.size, NODE_DEFAULT_SIZE[CanvasNodeType.Video].width, NODE_DEFAULT_SIZE[CanvasNodeType.Video].height) || NODE_DEFAULT_SIZE[CanvasNodeType.Video];
|
||||
const isEmptyVideoNode = sourceNode?.type === CanvasNodeType.Video && !sourceNode.metadata?.content;
|
||||
const isExistingVideoNode = sourceNode?.type === CanvasNodeType.Video && Boolean(sourceNode.metadata?.content);
|
||||
const videoId = isEmptyVideoNode ? nodeId : nanoid();
|
||||
const reuseSourceNode = canGenerateMediaInPlace(sourceNode, CanvasNodeType.Video);
|
||||
const isExistingVideoNode = sourceNode?.type === CanvasNodeType.Video && Boolean(sourceNode.metadata?.content) && !reuseSourceNode;
|
||||
const videoId = reuseSourceNode ? nodeId : nanoid();
|
||||
const versionRootId = isExistingVideoNode && sourceNode ? sourceNode.metadata?.versionOfNodeId || sourceNode.id : undefined;
|
||||
const parent = sourceNode?.position || { x: 0, y: 0 };
|
||||
const videoGenerationMetadata = buildVideoGenerationMetadata(sourceNode, generationContext, generationConfig);
|
||||
@@ -43,11 +44,11 @@ export async function executeVideoGeneration({
|
||||
id: videoId,
|
||||
type: CanvasNodeType.Video,
|
||||
title: effectivePrompt.slice(0, 32) || "Generated Video",
|
||||
position: isEmptyVideoNode ? sourceNode.position : { x: parent.x + (sourceNode?.width || spec.width) + 96, y: parent.y },
|
||||
width: isEmptyVideoNode ? sourceNode.width : spec.width,
|
||||
height: isEmptyVideoNode ? sourceNode.height : spec.height,
|
||||
position: reuseSourceNode ? sourceNode!.position : { x: parent.x + (sourceNode?.width || spec.width) + 96, y: parent.y },
|
||||
width: reuseSourceNode ? sourceNode!.width : spec.width,
|
||||
height: reuseSourceNode ? sourceNode!.height : spec.height,
|
||||
metadata: {
|
||||
...(isEmptyVideoNode ? sourceNode.metadata || {} : {}),
|
||||
...(reuseSourceNode ? sourceNode?.metadata || {} : {}),
|
||||
prompt: effectivePrompt,
|
||||
status: NODE_STATUS_LOADING,
|
||||
errorDetails: undefined,
|
||||
@@ -69,7 +70,7 @@ export async function executeVideoGeneration({
|
||||
registerPendingNodeIds([videoId]);
|
||||
// 待生成版本先加入版本族,但只有成功结果才能替换当前主版本。
|
||||
setNodes((current) => {
|
||||
if (isEmptyVideoNode) return current.map((node) => (node.id === nodeId ? { ...node, ...videoNode } : node));
|
||||
if (reuseSourceNode) return current.map((node) => (node.id === nodeId ? { ...node, ...videoNode } : node));
|
||||
if (!isExistingVideoNode || !sourceNode) return [...current.map((node) => (node.id === nodeId ? { ...node, metadata: { ...node.metadata, status: NODE_STATUS_SUCCESS } } : node)), videoNode];
|
||||
const rootId = versionRootId!;
|
||||
const nextLabel = nextCanvasVersionLabel(rootId, current);
|
||||
@@ -83,7 +84,7 @@ export async function executeVideoGeneration({
|
||||
];
|
||||
});
|
||||
// 重新生成已有视频时,新节点继承源视频的上游连接,与源视频保持并行关系,而不是作为其下游子节点。
|
||||
if (!isEmptyVideoNode) {
|
||||
if (!reuseSourceNode) {
|
||||
setConnections((current) => {
|
||||
if (!isExistingVideoNode) return [...current, { id: nanoid(), fromNodeId: nodeId, toNodeId: videoId }];
|
||||
return [...current, ...canvasConnections.filter((connection) => connection.toNodeId === nodeId).map((connection) => ({ ...connection, id: nanoid(), toNodeId: videoId }))];
|
||||
|
||||
Reference in new issue
Block a user