Files
xiaoxia-saas/apps/web/src/api/tasks.ts
T
xiaoxia e925ed3f54
CI/CD Pipeline / Frontend Lint (push) Successful in 56s
CI/CD Pipeline / Check if frontend-only change (push) Has been cancelled
CI/CD Pipeline / Validate Code Quality And Tests (push) Has been cancelled
CI/CD Pipeline / Unit Tests (push) Has been cancelled
CI/CD Pipeline / Integration Tests (push) Has been cancelled
CI/CD Pipeline / Frontend Unit Tests (push) Has been cancelled
CI Build & Deploy Pipeline / Build Staging API Image (push) Successful in 5m3s
CI Build & Deploy Pipeline / Build Staging Web Image (push) Successful in 27s
CI Build & Deploy Pipeline / Build Staging Worker Image (push) Successful in 7m25s
CI Build & Deploy Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Successful in 59s
CI Build & Deploy Pipeline / Staging E2E Tests (push) Waiting to run
CI Build & Deploy Pipeline / Staging API Integration Tests (push) Waiting to run
CI Build & Deploy Pipeline / Build Production API Image (push) Has been skipped
CI Build & Deploy Pipeline / Build Production Web Image (push) Has been skipped
CI Build & Deploy Pipeline / Build Production Worker Image (push) Has been skipped
CI Build & Deploy Pipeline / Deploy Production (push) Has been skipped
CI Build & Deploy Pipeline / Production Browser E2E (push) Has been skipped
feat(P1): 一键生成改智能剪辑 + 模板只展示系统预设 (#555)
Co-authored-by: xiaoxia <dev@xiaoxiajianji.com>
Co-committed-by: xiaoxia <dev@xiaoxiajianji.com>
2026-07-19 09:44:01 +08:00

124 lines
3.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 任务相关 API
* 对接后端任务中心 API
* - POST /api/v1/generation/tasks — 创建生成任务
* - GET /api/v1/tasks — 用户级任务列表(支持分页/筛选)
* - GET /api/v1/tasks/{task_id} — 任务详情(含 error_info
* - POST /api/v1/tasks/{task_id}/retry — 重试失败任务
*/
import apiClient from "./client"
/* ──────────── 类型定义 ──────────── */
/** 任务状态 */
export type TaskStatus = "pending" | "waiting" | "running" | "completed" | "failed" | "cancelled"
/** 任务类型 */
export type TaskType = "ingest" | "generation" | string
/** 错误详情 */
export interface TaskErrorInfo {
error_type: string
error_message: string
failed_step: string
stack_trace?: string
}
/** 任务条目(对应用户级 UserTaskResponse */
export interface TaskItem {
id: string
task_type: TaskType
project_id: string
template_id?: string
status: TaskStatus
progress: number
current_step: string
error_message: string
user_message: string
retryable: boolean
source_id: string
/** 错误详情(失败任务) */
error_info?: TaskErrorInfo
/** 耗时(秒) */
duration_seconds?: number
created_at?: string | null
updated_at?: string | null
}
/** 任务列表查询参数 */
export interface TaskListParams {
page?: number
page_size?: number
status?: TaskStatus | "all"
task_type?: TaskType | "all"
}
/** 任务列表分页响应 */
export interface TaskListResponse {
items: TaskItem[]
total: number
page: number
page_size: number
}
/** 创建生成任务请求参数 */
export interface CreateGenerationTaskRequest {
template_id: string
asset_ids: string[]
title_ids: string[]
voice_ids: string[]
}
/** 创建生成任务响应(对齐后端 GenerationTaskResponse */
export interface CreateGenerationTaskResponse {
id: string
project_id: string
asset_library_id: string
strategy_id: string
voice_library_id: string
template_id: string
asset_ids: string[]
title_ids: string[]
voice_ids: string[]
status: string
progress: number
result_count: number
error_message: string
}
/* ──────────── API 函数 ──────────── */
/** 创建生成任务(智能剪辑) */
export const createGenerationTask = async (
params: CreateGenerationTaskRequest,
): Promise<CreateGenerationTaskResponse> => {
const { data } = await apiClient.post<CreateGenerationTaskResponse>("/generation/tasks", params)
return data
}
/** 获取任务列表(支持分页和筛选) */
export const getTasks = async (params?: TaskListParams): Promise<TaskListResponse> => {
const { data } = await apiClient.get<TaskListResponse>("/tasks", {
params,
})
return data
}
/** 获取当前用户的所有任务(兼容旧接口,跨 project) */
export const getUserTasks = async (): Promise<TaskItem[]> => {
const { data } = await apiClient.get("/tasks")
return data.items || data || []
}
/** 获取单个任务详情(含 error_info */
export const getTask = async (taskId: string): Promise<TaskItem> => {
const { data } = await apiClient.get(`/tasks/${taskId}`)
return data
}
/** 重试失败的任务 */
export const retryTask = async (taskId: string): Promise<TaskItem> => {
const { data } = await apiClient.post(`/tasks/${taskId}/retry`)
return data
}