92 lines
2.9 KiB
TypeScript
92 lines
2.9 KiB
TypeScript
/**
|
|
* 模板草稿 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<EditPlanListResponse> {
|
|
const response = await apiClient.get<EditPlanListResponse>("/templates/drafts", {
|
|
params,
|
|
})
|
|
return response.data
|
|
}
|
|
|
|
/** 获取单个模板草稿 */
|
|
export async function getEditPlan(templateId: string): Promise<EditPlan> {
|
|
const response = await apiClient.get(`/templates/${templateId}/editor`)
|
|
return response.data
|
|
}
|
|
|
|
/** 创建模板草稿 */
|
|
export async function createEditPlan(data: CreateEditPlanRequest): Promise<EditPlan> {
|
|
const response = await apiClient.post("/templates/drafts", data)
|
|
return response.data
|
|
}
|
|
|
|
/** 更新模板草稿 */
|
|
export async function updateEditPlan(
|
|
templateId: string,
|
|
data: UpdateEditPlanRequest,
|
|
): Promise<EditPlan> {
|
|
const response = await apiClient.put(`/templates/${templateId}/editor`, data)
|
|
return response.data
|
|
}
|
|
|
|
/** 删除模板草稿 */
|
|
export async function deleteEditPlan(templateId: string): Promise<void> {
|
|
await apiClient.delete(`/templates/${templateId}/editor`)
|
|
}
|
|
|
|
/** 触发生成 */
|
|
export async function generateEditPlan(templateId: string): Promise<GenerateResponse> {
|
|
const response = await apiClient.post(`/templates/${templateId}/editor/generate`)
|
|
return response.data
|
|
}
|
|
|
|
/** 获取生成状态(轮询用) */
|
|
export async function getGenerationStatus(templateId: string): Promise<GenerationStatusResponse> {
|
|
const response = await apiClient.get(`/templates/${templateId}/editor/generation-status`)
|
|
return response.data
|
|
}
|
|
|
|
/** 获取模板草稿关联的生成记录 */
|
|
export async function getEditPlanGenerations(templateId: string): Promise<EditPlanGeneration[]> {
|
|
const response = await apiClient.get(`/templates/${templateId}/editor/generations`)
|
|
return response.data.items || []
|
|
}
|
|
|
|
/** 获取生成任务的视频结果列表 */
|
|
export async function getGenerationTaskResults(taskId: string): Promise<GeneratedVideo[]> {
|
|
const response = await apiClient.get(`/generation/tasks/${taskId}/results`)
|
|
return response.data.items || response.data || []
|
|
}
|
|
|
|
/** 取消生成任务 */
|
|
export async function cancelGeneration(templateId: string): Promise<void> {
|
|
await apiClient.post(`/templates/${templateId}/editor/cancel`)
|
|
}
|
|
|
|
/** 复制模板草稿(含所有片段配置) */
|
|
export async function copyEditPlan(
|
|
templateId: string,
|
|
data?: CopyEditPlanRequest,
|
|
): Promise<EditPlan> {
|
|
const response = await apiClient.post<EditPlan>(
|
|
`/templates/${templateId}/editor/copy`,
|
|
data || {},
|
|
)
|
|
return response.data
|
|
}
|