5e8dcb9843
- 移除 handleGenerate 中 from-assets 重复调用(useStep2Materials 已在选素材时 debounce 800ms 调用) - createClipsFromAssets 单独设置 60s timeout(与后端 MediaKit 一致),支持 AbortSignal - 调 generate 前轮询 listClips 确认存在 ready 片段,未就绪显示'正在智能选片中,请稍候...' - 轮询最多 90s(MediaKit 60s + 缓冲),超时提示'智能选片超时,请重试' - from-assets 请求超时/失败在 useStep2Materials 中 message.error 友好提示
111 lines
3.1 KiB
TypeScript
111 lines
3.1 KiB
TypeScript
/**
|
|
* 片段 CRUD + 批量操作 API
|
|
*/
|
|
import apiClient from "../client"
|
|
import type {
|
|
EditPlanClip,
|
|
EditPlanClipListParams,
|
|
EditPlanClipListResponse,
|
|
CreateEditPlanClipRequest,
|
|
UpdateEditPlanClipRequest,
|
|
ClipReorderItem,
|
|
ClipReorderResponse,
|
|
ClipBatchDeleteResponse,
|
|
ClipsFromAssetsResponse,
|
|
} from "./types"
|
|
|
|
/** 获取片段列表 */
|
|
export async function getEditPlanClips(
|
|
templateId: string,
|
|
params?: EditPlanClipListParams,
|
|
): Promise<EditPlanClipListResponse> {
|
|
const response = await apiClient.get<EditPlanClipListResponse>(
|
|
`/templates/${templateId}/editor/clips`,
|
|
{ params },
|
|
)
|
|
return response.data
|
|
}
|
|
|
|
/** 获取单个片段详情 */
|
|
export async function getEditPlanClip(templateId: string, clipId: string): Promise<EditPlanClip> {
|
|
const response = await apiClient.get<EditPlanClip>(
|
|
`/templates/${templateId}/editor/clips/${clipId}`,
|
|
)
|
|
return response.data
|
|
}
|
|
|
|
/** 创建片段 */
|
|
export async function createEditPlanClip(
|
|
templateId: string,
|
|
data: CreateEditPlanClipRequest,
|
|
): Promise<EditPlanClip> {
|
|
const response = await apiClient.post<EditPlanClip>(`/templates/${templateId}/editor/clips`, data)
|
|
return response.data
|
|
}
|
|
|
|
/** 更新片段 */
|
|
export async function updateEditPlanClip(
|
|
templateId: string,
|
|
clipId: string,
|
|
data: UpdateEditPlanClipRequest,
|
|
): Promise<EditPlanClip> {
|
|
const response = await apiClient.put<EditPlanClip>(
|
|
`/templates/${templateId}/editor/clips/${clipId}`,
|
|
data,
|
|
)
|
|
return response.data
|
|
}
|
|
|
|
/** 删除片段 */
|
|
export async function deleteEditPlanClip(templateId: string, clipId: string): Promise<void> {
|
|
await apiClient.delete(`/templates/${templateId}/editor/clips/${clipId}`)
|
|
}
|
|
|
|
/** 片段重排序(拖拽排序后一次性提交) */
|
|
export async function reorderEditPlanClips(
|
|
templateId: string,
|
|
items: ClipReorderItem[],
|
|
): Promise<ClipReorderResponse> {
|
|
const response = await apiClient.post<ClipReorderResponse>(
|
|
`/templates/${templateId}/editor/clips/reorder`,
|
|
{ items },
|
|
)
|
|
return response.data
|
|
}
|
|
|
|
/** 批量删除片段 */
|
|
export async function batchDeleteEditPlanClips(
|
|
templateId: string,
|
|
clipIds: string[],
|
|
): Promise<ClipBatchDeleteResponse> {
|
|
const response = await apiClient.post<ClipBatchDeleteResponse>(
|
|
`/templates/${templateId}/editor/clips/batch-delete`,
|
|
{ clip_ids: clipIds },
|
|
)
|
|
return response.data
|
|
}
|
|
|
|
/** 从素材批量创建片段(追加到时间线末尾) */
|
|
export async function createClipsFromAssets(
|
|
templateId: string,
|
|
assetIds: string[],
|
|
clipType = "main",
|
|
requiredClipsCount?: number,
|
|
opts?: { signal?: AbortSignal },
|
|
): Promise<ClipsFromAssetsResponse> {
|
|
const body: Record<string, unknown> = {
|
|
asset_ids: assetIds,
|
|
clip_type: clipType,
|
|
}
|
|
if (requiredClipsCount !== undefined) {
|
|
body.required_clips_count = requiredClipsCount
|
|
}
|
|
// from-assets 后端会调用 MediaKit 智能选片(最长 60s),单独延长超时
|
|
const response = await apiClient.post<ClipsFromAssetsResponse>(
|
|
`/templates/${templateId}/editor/clips/from-assets`,
|
|
body,
|
|
{ timeout: 60000, signal: opts?.signal },
|
|
)
|
|
return response.data
|
|
}
|