aa4b490578
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 170h50m55s
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Failing after 170h51m0s
Deploy / Deploy Staging (push) Failing after 170h51m13s
CI/CD Pipeline / Frontend Lint (push) Failing after 170h51m13s
CI/CD Pipeline / Validate Code Quality And Tests (push) Failing after 170h51m20s
- editPlans.ts: 按后端 Edit Plans Schema 重写所有 API 函数 - getEditPlans/getEditPlanDetail/createEditPlan/updateEditPlan/deleteEditPlan - generateEditPlan/getGenerationStatus 对接真实接口 - getMediaAssets/getAssetLibraries 传 libraryId 参数 - AssetResponse 字段直接映射(thumbnail_url/duration/width/height 等) - EditingPlanner.tsx: handleSave 传参匹配 CreateEditPlanRequest - MediaPanel.tsx: 素材获取传 libraryId,移除未使用变量 - GeneratePage.tsx: 素材获取用真实 API,生成流程用轮询,移除未使用变量 - AssetSelector.tsx: 修复 TS 类型错误(onChange/buttonSize/未使用函数) - MyVoices.tsx: 修复 PageHead 导入(default export) - VoiceLibrary.tsx: 修复 PageHead 导入 + Modal 未使用 + Timeout 类型 TypeScript 零错误,严格匹配后端接口字段名。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
290 lines
7.9 KiB
TypeScript
290 lines
7.9 KiB
TypeScript
/**
|
||
* 剪辑计划 API — 对接后端 Edit Plans Schema
|
||
* 字段名严格匹配后端 API 响应
|
||
*/
|
||
import apiClient from "./client";
|
||
import type { AssetItem } from "./assets";
|
||
|
||
/* ============================================================
|
||
* 后端 API 类型(严格匹配后端 Schema)
|
||
* ============================================================ */
|
||
|
||
/** 剪辑计划状态枚举 */
|
||
export type EditPlanStatus =
|
||
| "draft"
|
||
| "editing"
|
||
| "rendering"
|
||
| "completed"
|
||
| "failed";
|
||
|
||
/** 剪辑计划(后端响应) */
|
||
export interface EditPlan {
|
||
id: string;
|
||
template_id: string;
|
||
name: string;
|
||
status: EditPlanStatus;
|
||
total_duration: number;
|
||
config: Record<string, unknown>;
|
||
created_at: string;
|
||
updated_at: string;
|
||
}
|
||
|
||
/** 创建剪辑计划请求(后端要求 template_id + name 必填) */
|
||
export interface CreateEditPlanRequest {
|
||
template_id: string;
|
||
name: string;
|
||
config?: Record<string, unknown>;
|
||
total_duration?: number;
|
||
}
|
||
|
||
/** 更新剪辑计划请求 */
|
||
export interface UpdateEditPlanRequest {
|
||
name?: string;
|
||
config?: Record<string, unknown>;
|
||
total_duration?: number;
|
||
status?: EditPlanStatus;
|
||
}
|
||
|
||
/** 生成响应 */
|
||
export interface GenerateResponse {
|
||
plan_id: string;
|
||
plan_status: EditPlanStatus;
|
||
generation_task_id: string;
|
||
clip_count: number;
|
||
}
|
||
|
||
/** 片段生成状态 */
|
||
export interface ClipStatusItem {
|
||
clip_id: string;
|
||
clip_type: string;
|
||
order: number;
|
||
status: string;
|
||
asset_id?: string;
|
||
text_content?: string;
|
||
duration?: number;
|
||
}
|
||
|
||
/** 生成状态轮询响应 */
|
||
export interface GenerationStatusResponse {
|
||
plan_id: string;
|
||
plan_status: EditPlanStatus;
|
||
generation_task_id?: string;
|
||
clips: ClipStatusItem[];
|
||
}
|
||
|
||
/* ============================================================
|
||
* 前端 UI 类型(EditingPlanner 组件依赖,保留兼容)
|
||
* ============================================================ */
|
||
|
||
/** 剪辑计划中的片段(UI 层类型) */
|
||
export interface EditPlanClip {
|
||
id: string;
|
||
template_segment_id: string;
|
||
/** 素材库中的素材 ID */
|
||
media_asset_id?: string;
|
||
/** 素材类型 */
|
||
material_type: "video" | "image" | "audio" | "voiceover";
|
||
/** 片段文案 */
|
||
script_text: string;
|
||
/** 实际时长(秒) */
|
||
duration: number;
|
||
/** 转场效果 */
|
||
transition?: TransitionEffect;
|
||
/** 排序 */
|
||
order: number;
|
||
}
|
||
|
||
/** 转场效果 */
|
||
export interface TransitionEffect {
|
||
type: "none" | "fade" | "dissolve" | "wipe" | "zoom" | "slide";
|
||
duration: number; // 转场时长(秒)
|
||
}
|
||
|
||
/** 素材库资产(UI 层类型,映射自后端 AssetResponse) */
|
||
export interface MediaAsset {
|
||
id: string;
|
||
name: string;
|
||
type: "video" | "image" | "audio";
|
||
/** 缩略图 URL */
|
||
thumbnail_url?: string;
|
||
/** 时长(秒),仅 video/audio */
|
||
duration?: number;
|
||
/** 文件大小(字节) */
|
||
size?: number;
|
||
/** 标签 */
|
||
tags: string[];
|
||
created_at: string;
|
||
/** 质量分 0-100 */
|
||
quality_score?: number;
|
||
/** 分类状态 */
|
||
classification_status?: "pending" | "processing" | "completed" | "failed";
|
||
}
|
||
|
||
/* ============================================================
|
||
* API 函数 — 严格对接后端
|
||
* ============================================================ */
|
||
|
||
/** 获取剪辑计划列表 */
|
||
export async function getEditPlans(params?: {
|
||
page?: number;
|
||
page_size?: number;
|
||
template_id?: string;
|
||
status?: string;
|
||
}): Promise<EditPlan[]> {
|
||
const response = await apiClient.get("/edit-plans", { params });
|
||
return response.data.items || [];
|
||
}
|
||
|
||
/** 获取单个剪辑计划 */
|
||
export async function getEditPlan(planId: string): Promise<EditPlan> {
|
||
const response = await apiClient.get(`/edit-plans/${planId}`);
|
||
return response.data;
|
||
}
|
||
|
||
/** 创建剪辑计划 */
|
||
export async function createEditPlan(
|
||
data: CreateEditPlanRequest,
|
||
): Promise<EditPlan> {
|
||
const response = await apiClient.post("/edit-plans", data);
|
||
return response.data;
|
||
}
|
||
|
||
/** 更新剪辑计划 */
|
||
export async function updateEditPlan(
|
||
planId: string,
|
||
data: UpdateEditPlanRequest,
|
||
): Promise<EditPlan> {
|
||
const response = await apiClient.put(`/edit-plans/${planId}`, data);
|
||
return response.data;
|
||
}
|
||
|
||
/** 删除剪辑计划 */
|
||
export async function deleteEditPlan(planId: string): Promise<void> {
|
||
await apiClient.delete(`/edit-plans/${planId}`);
|
||
}
|
||
|
||
/** 触发剪辑计划生成 */
|
||
export async function generateEditPlan(
|
||
planId: string,
|
||
): Promise<GenerateResponse> {
|
||
const response = await apiClient.post(`/edit-plans/${planId}/generate`);
|
||
return response.data;
|
||
}
|
||
|
||
/** 获取剪辑计划生成状态(轮询用) */
|
||
export async function getGenerationStatus(
|
||
planId: string,
|
||
): Promise<GenerationStatusResponse> {
|
||
const response = await apiClient.get(
|
||
`/edit-plans/${planId}/generation-status`,
|
||
);
|
||
return response.data;
|
||
}
|
||
|
||
/**
|
||
* 获取素材库列表 — 调用 GET /api/v1/assets?library_id=xxx
|
||
* 将后端 AssetResponse 映射为前端 MediaAsset 类型
|
||
*/
|
||
export async function getMediaAssets(
|
||
libraryId?: string,
|
||
): Promise<MediaAsset[]> {
|
||
const response = await apiClient.get("/assets", {
|
||
params: libraryId ? { library_id: libraryId } : undefined,
|
||
});
|
||
const items: AssetItem[] = response.data.items || [];
|
||
return items.map(mapAssetToMediaAsset);
|
||
}
|
||
|
||
/** 获取单个素材 */
|
||
export async function getMediaAsset(id: string): Promise<MediaAsset> {
|
||
const response = await apiClient.get(`/assets/${id}`);
|
||
return mapAssetToMediaAsset(response.data);
|
||
}
|
||
|
||
/* ============================================================
|
||
* 映射函数:AssetResponse → MediaAsset
|
||
* ============================================================ */
|
||
|
||
function inferMediaType(mimeType: string): "video" | "image" | "audio" {
|
||
if (mimeType.startsWith("video/")) return "video";
|
||
if (mimeType.startsWith("image/")) return "image";
|
||
return "audio";
|
||
}
|
||
|
||
function mapAssetToMediaAsset(asset: AssetItem): MediaAsset {
|
||
const meta = (asset.metadata || {}) as Record<string, unknown>;
|
||
const ext = asset as AssetItem & Record<string, unknown>;
|
||
return {
|
||
id: asset.id,
|
||
name: asset.name,
|
||
type: inferMediaType(asset.mime_type || ""),
|
||
thumbnail_url: typeof ext.thumbnail_url === "string" ? ext.thumbnail_url : undefined,
|
||
duration:
|
||
typeof ext.duration === "number"
|
||
? ext.duration
|
||
: typeof meta.duration === "number"
|
||
? (meta.duration as number)
|
||
: undefined,
|
||
size: asset.file_size ?? undefined,
|
||
tags: [],
|
||
created_at: asset.created_at ?? "",
|
||
quality_score: asset.quality_score ?? undefined,
|
||
classification_status: (asset.classification_status ?? undefined) as MediaAsset["classification_status"],
|
||
};
|
||
}
|
||
|
||
/* ============================================================
|
||
* 常量
|
||
* ============================================================ */
|
||
|
||
/** 转场效果选项 */
|
||
export const TRANSITION_OPTIONS: {
|
||
value: TransitionEffect["type"];
|
||
label: string;
|
||
}[] = [
|
||
{ value: "none", label: "无转场" },
|
||
{ value: "fade", label: "淡入淡出" },
|
||
{ value: "dissolve", label: "溶解" },
|
||
{ value: "wipe", label: "擦除" },
|
||
{ value: "zoom", label: "缩放" },
|
||
{ value: "slide", label: "滑动" },
|
||
];
|
||
|
||
/** 素材类型标签 */
|
||
export const MATERIAL_TYPE_LABELS: Record<string, string> = {
|
||
video: "视频",
|
||
image: "图片",
|
||
audio: "音频",
|
||
voiceover: "配音",
|
||
};
|
||
|
||
/** 素材类型图标 */
|
||
export const MATERIAL_TYPE_ICONS: Record<string, string> = {
|
||
video: "🎬",
|
||
image: "🖼️",
|
||
audio: "🎵",
|
||
voiceover: "🎙️",
|
||
};
|
||
|
||
/** 计划状态标签 */
|
||
export const PLAN_STATUS_LABELS: Record<EditPlanStatus, string> = {
|
||
draft: "草稿",
|
||
editing: "编辑中",
|
||
rendering: "渲染中",
|
||
completed: "已完成",
|
||
failed: "失败",
|
||
};
|
||
|
||
/** 质量分筛选选项 */
|
||
export const QUALITY_OPTIONS: {
|
||
value: string;
|
||
label: string;
|
||
min?: number;
|
||
max?: number;
|
||
}[] = [
|
||
{ value: "all", label: "全部质量" },
|
||
{ value: "high", label: "高质量 (80-100)", min: 80, max: 100 },
|
||
{ value: "medium", label: "中质量 (50-79)", min: 50, max: 79 },
|
||
{ value: "low", label: "低质量 (0-49)", min: 0, max: 49 },
|
||
];
|