/** * 模板草稿 CRUD + 生成相关 API */ import apiClient from "../client" import type { EditPlan, EditPlanListParams, EditPlanListResponse, CreateEditPlanRequest, UpdateEditPlanRequest, GenerateResponse, GenerationStatusResponse, EditPlanGeneration, GeneratedVideo, CopyEditPlanRequest, } from "./types" /** 获取模板草稿列表(支持分页和筛选) */ export async function getEditPlans(params?: EditPlanListParams): Promise { const response = await apiClient.get("/templates/drafts", { params, }) return response.data } /** 获取单个模板草稿 */ export async function getEditPlan(templateId: string): Promise { const response = await apiClient.get(`/templates/${templateId}/editor`) return response.data } /** 创建模板草稿 */ export async function createEditPlan(data: CreateEditPlanRequest): Promise { const response = await apiClient.post("/templates/drafts", data) return response.data } /** 更新模板草稿 */ export async function updateEditPlan( templateId: string, data: UpdateEditPlanRequest, ): Promise { const response = await apiClient.put(`/templates/${templateId}/editor`, data) return response.data } /** 删除模板草稿 */ export async function deleteEditPlan(templateId: string): Promise { await apiClient.delete(`/templates/${templateId}/editor`) } /** 触发生成 */ export async function generateEditPlan(templateId: string): Promise { const response = await apiClient.post(`/templates/${templateId}/editor/generate`) return response.data } /** 获取生成状态(轮询用) */ export async function getGenerationStatus(templateId: string): Promise { const response = await apiClient.get(`/templates/${templateId}/editor/generation-status`) return response.data } /** 获取模板草稿关联的生成记录 */ export async function getEditPlanGenerations(templateId: string): Promise { const response = await apiClient.get(`/templates/${templateId}/editor/generations`) return response.data.items || [] } /** 获取生成任务的视频结果列表 */ export async function getGenerationTaskResults(taskId: string): Promise { const response = await apiClient.get(`/generation/tasks/${taskId}/results`) return response.data.items || response.data || [] } /** 取消生成任务 */ export async function cancelGeneration(templateId: string): Promise { await apiClient.post(`/templates/${templateId}/editor/cancel`) } /** 复制模板草稿(含所有片段配置) */ export async function copyEditPlan( templateId: string, data?: CopyEditPlanRequest, ): Promise { const response = await apiClient.post( `/templates/${templateId}/editor/copy`, data || {}, ) return response.data }