fix: createGenerationTask 返回值取 items[0],ID 前缀逻辑修正
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 2m15s
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Failing after 6m39s
CI/CD Pipeline / Build & Push Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Build Production Runtime Images (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 2m15s
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Failing after 6m39s
CI/CD Pipeline / Build & Push Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Build Production Runtime Images (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
- createGenerationTask 返回 BatchGenerationTaskResponse {items, total},
之前错误地直接用 res.id(undefined),改为 res.items[0].id
- 后端返回裸 UUID,任务中心 getTask 需要 generation: 前缀,
创建后补前缀再查询;轮询/重试直接用 genTask.id(已带前缀)
- 新增空数组保护,无任务时抛出明确错误
This commit is contained in:
Regular → Executable
+12
-3
@@ -35,7 +35,7 @@ export interface CreateGenerationTaskRequest {
|
||||
}
|
||||
|
||||
/** 创建生成任务响应(对齐后端 GenerationTaskResponse) */
|
||||
export interface CreateGenerationTaskResponse {
|
||||
export interface GenerationTaskItem {
|
||||
id: string;
|
||||
project_id: string;
|
||||
asset_library_id: string;
|
||||
@@ -51,13 +51,22 @@ export interface CreateGenerationTaskResponse {
|
||||
error_message: string;
|
||||
}
|
||||
|
||||
/** 批量创建响应(对齐后端 BatchGenerationTaskResponse) */
|
||||
export interface BatchGenerationTaskResponse {
|
||||
items: GenerationTaskItem[];
|
||||
total: number;
|
||||
}
|
||||
|
||||
/** @deprecated 请使用 GenerationTaskItem */
|
||||
export type CreateGenerationTaskResponse = GenerationTaskItem;
|
||||
|
||||
/* ──────────── API 函数 ──────────── */
|
||||
|
||||
/** 创建生成任务(一键生成) */
|
||||
export const createGenerationTask = async (
|
||||
params: CreateGenerationTaskRequest,
|
||||
): Promise<CreateGenerationTaskResponse> => {
|
||||
const { data } = await apiClient.post<CreateGenerationTaskResponse>(
|
||||
): Promise<BatchGenerationTaskResponse> => {
|
||||
const { data } = await apiClient.post<BatchGenerationTaskResponse>(
|
||||
"/generation/tasks",
|
||||
params,
|
||||
);
|
||||
|
||||
@@ -506,12 +506,17 @@ const EditingPlanner: React.FC = () => {
|
||||
voice_ids: voiceIds,
|
||||
});
|
||||
/*
|
||||
* 后端 Tasks API 使用带前缀的 ID(如 generation:xxx),
|
||||
* 但 createGenerationTask 返回的是裸 UUID,需补上前缀。
|
||||
* createGenerationTask 返回批量响应 {items, total},
|
||||
* 取第一个任务的 ID。后端返回裸 UUID,
|
||||
* 但任务中心 API(getTask)使用带前缀的 ID(generation:xxx),
|
||||
* 需补前缀后再查询。
|
||||
*/
|
||||
const taskId = res.id.includes(":")
|
||||
? res.id
|
||||
: `generation:${res.id}`;
|
||||
const firstTask = res.items?.[0];
|
||||
if (!firstTask) {
|
||||
throw new Error("创建生成任务失败:无返回任务");
|
||||
}
|
||||
const rawId = firstTask.id;
|
||||
const taskId = rawId.includes(":") ? rawId : `generation:${rawId}`;
|
||||
/* 创建接口返回的是精简响应,需查询完整 TaskItem 用于轮询 */
|
||||
const task = await getTask(taskId);
|
||||
setGenTask(task);
|
||||
|
||||
Reference in New Issue
Block a user