Files
xiaoxia-saas/apps/web/src/api/tasks.ts
T
灵应 6ce40d76ea
Deploy / Build Production Runtime Images (push) Has been skipped
Deploy / Deploy Production (push) Has been skipped
Deploy / Production Browser E2E (push) Has been skipped
CI/CD Pipeline / Frontend Lint (pull_request) Failing after 186h43m22s
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Failing after 186h43m25s
Deploy / Deploy Staging (push) Failing after 186h43m53s
CI/CD Pipeline / Frontend Lint (push) Failing after 186h44m20s
CI/CD Pipeline / Validate Code Quality And Tests (push) Failing after 186h44m24s
feat(editing-planner): 实现生成进度展示 — 任务 2.17
- 新增 GenerationProgressModal 组件:三阶段 UI(setup → progress → completed/failed)
- 集成 React Query 轮询:refetchInterval 2s 轮询任务状态,终态自动停止
- 进度展示:SVG 进度环 + 进度条 + 步骤文案 + 任务 ID
- 失败处理:错误信息展示 + 可重试时显示重试按钮
- 对接 createGenerationTask / getTask / retryTask API
- V21 设计系统,CSS 类名前缀 ep-gen-
2026-07-01 18:09:58 +08:00

84 lines
2.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
* 对接后端方案 A 扩展后的端点(PR #109)
* - POST /api/v1/generation/tasks — 创建生成任务(template_id + asset_ids 细粒度模式)
* - GET /api/v1/tasks — 用户级任务列表(跨 project)
* - POST /api/v1/tasks/{task_id}/retry — 简化重试
*/
import apiClient from "./client";
/* ──────────── 类型定义 ──────────── */
/** 任务条目(对应用户级 UserTaskResponse */
export interface TaskItem {
id: string;
task_type: "ingest" | "generation" | string;
project_id: string;
template_id: string;
status: string;
progress: number;
current_step: string;
error_message: string;
user_message: string;
retryable: boolean;
source_id: string;
created_at?: string | null;
updated_at?: string | null;
}
/** 创建生成任务请求参数 */
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;
};
/** 获取当前用户的所有任务(跨 project) */
export const getUserTasks = async (): Promise<TaskItem[]> => {
const { data } = await apiClient.get("/tasks");
return data.items || [];
};
/** 获取单个任务详情(用于轮询进度) */
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;
};