/** * 模板草稿 CRUD API */ import apiClient from "../client" import type { EditPlan, UpdateEditPlanRequest, GeneratedVideo } from "./types" /** 获取单个模板草稿 */ export async function getEditPlan(templateId: string): Promise { const response = await apiClient.get(`/templates/${templateId}/editor`) return response.data } /** 更新模板草稿(支持传入 AbortSignal 用于自动保存竞态取消) */ export async function updateEditPlan( templateId: string, data: UpdateEditPlanRequest, signal?: AbortSignal, ): Promise { const response = await apiClient.put(`/templates/${templateId}/editor`, data, { signal }) return response.data } /** 获取生成任务的视频结果列表 */ export async function getGenerationTaskResults(taskId: string): Promise { const response = await apiClient.get(`/generation/tasks/${taskId}/results`) return response.data.items || response.data || [] } /** ── 草稿 clips 批量更新 ── */ export interface EditPlanClipInput { asset_id: string start_time: number duration: number order: number } /** * 批量替换草稿的 clips(先全删再批量插入) * 后端路由:PUT /templates/{template_id}/editor/clips */ export async function updateEditPlanClips( templateId: string, clips: EditPlanClipInput[], signal?: AbortSignal, /** 为 true 时抑制全局错误 toast(调用方自行提示,如失效模板回退 #1777) */ silentErrorToast?: boolean, ): Promise<{ count: number }> { const response = await apiClient.put( `/templates/${templateId}/editor/clips`, { clips }, { signal, // _silentErrorToast 由 api/client.ts 响应拦截器读取(抑制全局错误 toast) ...(silentErrorToast ? ({ _silentErrorToast: true } as Record) : {}), }, ) return response.data }