From 46fc84902e47ba2c9b0f2cc103e4dad93e3e1174 Mon Sep 17 00:00:00 2001 From: CI Bot Date: Wed, 26 Aug 2026 22:06:17 +0800 Subject: [PATCH] =?UTF-8?q?fix(editor):=20=E5=93=8D=E5=BA=94AI=20Review?= =?UTF-8?q?=EF=BC=9B=E9=BB=98=E8=AE=A4=E6=97=B6=E9=95=BF=E6=8F=90=E4=B8=BA?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E5=B8=B8=E9=87=8F=EF=BC=9Blist=5Fclips?= =?UTF-8?q?=E6=98=BE=E5=BC=8FList=E7=B1=BB=E5=9E=8B=E6=A0=87=E6=B3=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/api/app/api/routes/templates_editor/clips.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/apps/api/app/api/routes/templates_editor/clips.py b/apps/api/app/api/routes/templates_editor/clips.py index 41a05f6f1..515e3eaa4 100755 --- a/apps/api/app/api/routes/templates_editor/clips.py +++ b/apps/api/app/api/routes/templates_editor/clips.py @@ -46,6 +46,9 @@ from .schemas import ( logger = logging.getLogger(__name__) router = APIRouter(tags=["Template Editor"]) +# 编辑器默认片段时长(秒) +_DEFAULT_EDITOR_CLIP_DURATION = 5.0 + def _clip_to_response(clip, asset_url: str | None = None) -> EditorClipResponse: """统一构造片段响应 — 与 edit_plan_clips 表字段完全对齐""" @@ -368,8 +371,7 @@ def create_clips_from_assets_editor( """ _, plan_svc = services - _DEFAULT_CLIP_DURATION = 5.0 - required_count = body.required_clips_count if body.required_clips_count else len(body.asset_ids) + required_count = body.required_clips_count if body.required_clips_count is not None else len(body.asset_ids) # 去重后批量获取素材实际时长,避免重复查询 unique_asset_ids = list(dict.fromkeys(body.asset_ids)) @@ -380,8 +382,9 @@ def create_clips_from_assets_editor( asset_durations[asset_id] = float(asset.duration or 0.0) # 计算追加起始 order:当前 plan 已有片段的最大 order + 1 - existing_clips = plan_svc.list_clips(plan_id) - next_order = max((c.order for c in existing_clips), default=-1) + 1 + # list_clips 返回 List[EditPlanClip] + existing_clips_list = plan_svc.list_clips(plan_id) + next_order = max((c.order for c in existing_clips_list), default=-1) + 1 used_segments: dict[str, list[tuple[float, float]]] = {} clips = [] @@ -393,9 +396,9 @@ def create_clips_from_assets_editor( # 素材时长不足时缩短 clip duration asset_total = asset_durations.get(asset_id, 0.0) if asset_total > 0: - clip_duration = min(_DEFAULT_CLIP_DURATION, asset_total) + clip_duration = min(_DEFAULT_EDITOR_CLIP_DURATION, asset_total) else: - clip_duration = _DEFAULT_CLIP_DURATION + clip_duration = _DEFAULT_EDITOR_CLIP_DURATION # 计算随机 start_time,避开已使用的时间段 start_time = _calc_random_start_time(asset_id, clip_duration, asset_durations, used_segments)