From ee704efc0bc2649479c5cf2a96f9c9637585caba Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Wed, 29 Jul 2026 21:59:30 +0800 Subject: [PATCH] =?UTF-8?q?refactor(generate):=20=E6=8F=90=E5=8F=96=20buil?= =?UTF-8?q?dPayload=20=E5=92=8C=20validateGenerateInputs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hooks/generate-video/buildPayload.ts | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 apps/web/src/pages/generate/hooks/generate-video/buildPayload.ts diff --git a/apps/web/src/pages/generate/hooks/generate-video/buildPayload.ts b/apps/web/src/pages/generate/hooks/generate-video/buildPayload.ts new file mode 100644 index 000000000..f4db27a8c --- /dev/null +++ b/apps/web/src/pages/generate/hooks/generate-video/buildPayload.ts @@ -0,0 +1,77 @@ +import type { UseGenerateVideoProps } from "./types" +import { buildVoiceConfig } from "./voiceConfig" + +/** + * 构建 updateEditPlan 的 payload + * 从 props 中提取需要的字段,组装成 API 所需的 config 结构 + */ +export const buildEditPlanPayload = (props: UseGenerateVideoProps) => { + const { + titleSettings, + selectedMaterials, + materialMode, + smartSelectedIds, + voiceMode, + selectedVoice, + selectedClonedVoice, + coverSettings, + videoRatio, + style, + duration, + autoSubtitles, + bgm, + generateCount, + } = props + + const voiceConfig = buildVoiceConfig({ + voiceMode, + selectedVoice, + selectedClonedVoice, + }) + + return { + name: titleSettings.title.trim(), + config: { + asset_ids: materialMode === "auto" ? smartSelectedIds : selectedMaterials, + title_config: { + ai_auto_select: titleSettings.aiAutoSelect, + content: titleSettings.title, + position: titleSettings.position, + font_preset: titleSettings.font, + font_color: titleSettings.color, + font_size: titleSettings.size, + }, + cover_config: coverSettings, + ...voiceConfig, + ratio: videoRatio, + style, + duration, + auto_subtitles: autoSubtitles, + bgm, + generate_count: generateCount, + material_mode: materialMode, + }, + total_duration: duration, + status: "editing" as const, + } +} + +/** + * 生成前置校验 + * 返回错误信息,通过则返回 null + */ +export const validateGenerateInputs = (props: UseGenerateVideoProps): string | null => { + const { titleSettings, materialMode, selectedMaterials, voiceMode, selectedClonedVoice } = props + + if (!titleSettings.title.trim()) { + return "请先选择或输入标题" + } + if (materialMode === "manual" && selectedMaterials.length === 0) { + return "请至少选择一个素材" + } + if (voiceMode === "clone" && !selectedClonedVoice) { + return "请先选择一个克隆音色" + } + return null +} +