From a25aa7baede25bd2da3e04b3b544074b04683c5d Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Tue, 15 Sep 2026 11:13:58 +0800 Subject: [PATCH] =?UTF-8?q?fix(generate):=20#1921=20from-assets=E7=A9=BAte?= =?UTF-8?q?mplateId=E5=8F=8C=E6=96=9C=E6=9D=A0404=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=EF=BC=88P0=E5=89=8D=E7=AB=AF=EF=BC=89=20(#1925)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: xiaoxia Co-committed-by: xiaoxia --- apps/web/src/api/template-editor/clips.ts | 27 +++++++++++++---------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/apps/web/src/api/template-editor/clips.ts b/apps/web/src/api/template-editor/clips.ts index 7a63ba843..8a3a70f0f 100644 --- a/apps/web/src/api/template-editor/clips.ts +++ b/apps/web/src/api/template-editor/clips.ts @@ -85,9 +85,13 @@ export async function batchDeleteEditPlanClips( return response.data } -/** 从素材批量创建片段(追加到时间线末尾) */ +/** + * 从素材批量创建片段(追加到时间线末尾)。 + * #1921 修复:templateId 为空时调用新端点 POST /clips/from-assets,避免拼出双斜杠 + * `/templates//editor/clips/from-assets` 导致 404;有 templateId 时保持原路径向后兼容。 + */ export async function createClipsFromAssets( - templateId: string, + templateId: string | undefined | null, assetIds: string[], clipType = "main", requiredClipsCount?: number, @@ -100,16 +104,15 @@ export async function createClipsFromAssets( if (requiredClipsCount !== undefined) { body.required_clips_count = requiredClipsCount } + // 新端点(#1921):templateId 为空时,body 不传 template_id,由后端兜底创建默认模板 + const hasTid = !!templateId + const url = hasTid ? `/templates/${templateId}/editor/clips/from-assets` : "/clips/from-assets" // from-assets 后端会调用 MediaKit 智能选片(最长 60s),单独延长超时 - const response = await apiClient.post( - `/templates/${templateId}/editor/clips/from-assets`, - body, - { - timeout: 60000, - signal: opts?.signal, - // _silentErrorToast 由 api/client.ts 响应拦截器读取(抑制全局错误 toast,#1777) - ...(opts?.silentErrorToast ? ({ _silentErrorToast: true } as Record) : {}), - }, - ) + const response = await apiClient.post(url, body, { + timeout: 60000, + signal: opts?.signal, + // _silentErrorToast 由 api/client.ts 响应拦截器读取(抑制全局错误 toast,#1777) + ...(opts?.silentErrorToast ? ({ _silentErrorToast: true } as Record) : {}), + }) return response.data }