fix(web): 修复生成页 API 调用适配新模板编辑器架构 (#671)
CI/CD Pipeline / Check if frontend-only change (push) Has been skipped
CI/CD Pipeline / Build Production Web Image (push) Has been skipped
CI/CD Pipeline / Build Production API Image (push) Has been skipped
CI/CD Pipeline / Build Production Worker Image (push) Has been skipped
CI/CD Pipeline / Deploy Production (push) Has been skipped
CI/CD Pipeline / Production Browser E2E (push) Has been skipped
CI/CD Pipeline / Build Staging Web Image (push) Successful in 5m56s
CI/CD Pipeline / Frontend Lint (push) Successful in 5m57s
CI/CD Pipeline / Unit Tests (push) Successful in 6m38s
CI/CD Pipeline / Frontend Unit Tests (push) Successful in 6m57s
CI/CD Pipeline / Validate Code Quality And Tests (push) Successful in 7m8s
CI/CD Pipeline / Integration Tests (push) Successful in 1m49s
CI/CD Pipeline / Build Staging API Image (push) Has been cancelled
CI/CD Pipeline / Build Staging Worker Image (push) Has been cancelled
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Has been cancelled
CI/CD Pipeline / Staging E2E Tests (push) Has been cancelled
CI/CD Pipeline / Staging API Integration Tests (push) Has been cancelled
CI/CD Pipeline / ACR Image Cleanup (push) Has been cancelled

Co-authored-by: xiaoxia <dev@xiaoxiajianji.com>
Co-committed-by: xiaoxia <dev@xiaoxiajianji.com>
This commit was merged in pull request #671.
This commit is contained in:
2026-07-21 10:33:47 +08:00
committed by auto-approve-bot
parent 269723ced2
commit beabc932e6
4 changed files with 42 additions and 32 deletions
+11 -13
View File
@@ -25,11 +25,11 @@ import {
import type { AssetItem } from "@/api/assets"
import { getAssets, getAssetLibraries } from "@/api/assets"
import {
createEditPlan,
generateEditPlan,
updateEditPlan,
getGenerationTaskResults,
getGenerationStatus,
getEditPlan,
} from "@/api/templateEditor"
import type { GeneratedVideo, EditPlanConfig, TitleConfig } from "@/api/templateEditor"
import type { CoverConfig } from "../editing-planner/types"
@@ -44,7 +44,6 @@ import { synthesizeSpeech, getTTSJobStatus, saveTtsToLibrary } from "@/api/tts"
import { getTags, createTag } from "@/api/tags"
import { useCloneProgress } from "@/hooks/useCloneProgress"
import { useSearchParams, useNavigate } from "react-router-dom"
import { getEditPlan } from "@/api/templateEditor"
import "./generate.css"
const { Text } = Typography
@@ -994,8 +993,11 @@ const GeneratePage: React.FC = () => {
if (customVoiceText.trim()) voiceConfig.custom_text = customVoiceText.trim()
}
const plan = await createEditPlan({
template_id: selectedTemplate,
// 获取或创建草稿(新架构:GET /templates/{templateId}/editor 自动创建)
await getEditPlan(selectedTemplate)
// 更新草稿内容 + 切换到 editing 状态
await updateEditPlan(selectedTemplate, {
name: titleSettings.title.trim(),
config: {
asset_ids: materialMode === "auto" ? smartSelectedIds : selectedMaterials,
@@ -1018,17 +1020,14 @@ const GeneratePage: React.FC = () => {
material_mode: materialMode,
},
total_duration: duration,
source_edit_plan_id: editPlanId || undefined,
status: "editing",
})
// 后端要求计划处于 editing 状态才能触发渲染,自动转换状态
await updateEditPlan(plan.id, { status: "editing" })
await generateEditPlan(plan.id)
await generateEditPlan(selectedTemplate)
const poll = async () => {
try {
const data = await getGenerationStatus(plan.id)
const data = await getGenerationStatus(selectedTemplate)
if (data.plan_status === "completed") {
setProgress(100)
@@ -1075,7 +1074,7 @@ const GeneratePage: React.FC = () => {
return String(val ?? "")
}
const errorMsg = safeExtract(rawMsg)
console.error("[生成失败] planId:", plan.id, "响应:", data)
console.error("[生成失败] templateId:", selectedTemplate, "响应:", data)
setGenerateError(errorMsg)
message.error(errorMsg)
return
@@ -1091,7 +1090,7 @@ const GeneratePage: React.FC = () => {
>
} catch (pollErr) {
// 轮询接口本身出错(网络/鉴权等),记录并继续轮询一次
console.error("[轮询出错] planId:", plan.id, pollErr)
console.error("[轮询出错] templateId:", selectedTemplate, pollErr)
progressTimer.current = setTimeout(poll, 3000) as unknown as ReturnType<
typeof setInterval
>
@@ -1198,7 +1197,6 @@ const GeneratePage: React.FC = () => {
duration,
autoSubtitles,
bgm,
editPlanId,
selectedTemplate,
generateCount,
materialMode,
View File
+17 -4
View File
@@ -214,10 +214,23 @@ vi.mock("@/api/titles", () => ({
}))
vi.mock("@/api/templateEditor", () => ({
createEditPlan: vi.fn().mockResolvedValue({ id: "test-plan" }),
generateEditPlan: vi.fn().mockResolvedValue({ task_id: "test-task" }),
updateEditPlan: vi.fn().mockResolvedValue({}),
getEditPlan: vi.fn().mockResolvedValue({}),
generateEditPlan: vi.fn().mockResolvedValue({
plan_id: "test-plan",
generation_task_id: "test-task",
plan_status: "processing",
clip_count: 5,
}),
updateEditPlan: vi.fn().mockResolvedValue({ plan_id: "test-plan", template_id: "test-template" }),
getEditPlan: vi.fn().mockResolvedValue({
plan_id: "test-plan",
template_id: "test-template",
name: "",
config: {},
status: "draft",
}),
getGenerationStatus: vi
.fn()
.mockResolvedValue({ plan_status: "completed", generation_task_id: "test-task", clips: [] }),
getGenerationTaskResults: vi.fn().mockResolvedValue({ items: [] }),
}))