#456 修复创建剪辑计划时传template_id不生成clips的问题 (#460)
CI/CD Pipeline / Check if frontend-only change (push) Has been skipped
CI Build & Deploy Pipeline / Build Production API Image (push) Has been skipped
CI Build & Deploy Pipeline / Build Production Web Image (push) Has been skipped
CI Build & Deploy Pipeline / Build Production Worker Image (push) Has been skipped
CI Build & Deploy Pipeline / Deploy Production (push) Has been skipped
CI Build & Deploy Pipeline / Production Browser E2E (push) Has been skipped
CI Build & Deploy Pipeline / Build Staging Web Image (push) Successful in 22s
CI/CD Pipeline / Frontend Lint (push) Successful in 36s
CI/CD Pipeline / Validate Code Quality And Tests (push) Successful in 3m8s
CI/CD Pipeline / Unit Tests (push) Successful in 3m11s
CI/CD Pipeline / Integration Tests (push) Successful in 1m24s
CI Build & Deploy Pipeline / Build Staging API Image (push) Successful in 7m25s
CI Build & Deploy Pipeline / Build Staging Worker Image (push) Successful in 8m16s
CI Build & Deploy Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Successful in 1m7s
CI Build & Deploy Pipeline / Staging API Integration Tests (push) Successful in 3m38s
CI Build & Deploy Pipeline / Staging E2E Tests (push) Failing after 3m48s
CI/CD Pipeline / Check if frontend-only change (push) Has been skipped
CI Build & Deploy Pipeline / Build Production API Image (push) Has been skipped
CI Build & Deploy Pipeline / Build Production Web Image (push) Has been skipped
CI Build & Deploy Pipeline / Build Production Worker Image (push) Has been skipped
CI Build & Deploy Pipeline / Deploy Production (push) Has been skipped
CI Build & Deploy Pipeline / Production Browser E2E (push) Has been skipped
CI Build & Deploy Pipeline / Build Staging Web Image (push) Successful in 22s
CI/CD Pipeline / Frontend Lint (push) Successful in 36s
CI/CD Pipeline / Validate Code Quality And Tests (push) Successful in 3m8s
CI/CD Pipeline / Unit Tests (push) Successful in 3m11s
CI/CD Pipeline / Integration Tests (push) Successful in 1m24s
CI Build & Deploy Pipeline / Build Staging API Image (push) Successful in 7m25s
CI Build & Deploy Pipeline / Build Staging Worker Image (push) Successful in 8m16s
CI Build & Deploy Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Successful in 1m7s
CI Build & Deploy Pipeline / Staging API Integration Tests (push) Successful in 3m38s
CI Build & Deploy Pipeline / Staging E2E Tests (push) Failing after 3m48s
Co-authored-by: xiaoxia <dev@xiaoxiajianji.com> Co-committed-by: xiaoxia <dev@xiaoxiajianji.com>
This commit was merged in pull request #460.
This commit is contained in:
Regular → Executable
+67
-9
@@ -365,36 +365,94 @@ def create_plan(
|
||||
current_user: AuthenticatedUser = Depends(get_current_user),
|
||||
project_repository: Any = Depends(get_project_repository),
|
||||
) -> EditPlanResponse:
|
||||
"""创建剪辑计划"""
|
||||
"""创建剪辑计划
|
||||
|
||||
基于模板自动生成片段结构:
|
||||
- 模板存在时:从模板的 clip_configs 生成初始 clips
|
||||
- 模板不存在时:降级为空计划(保持向后兼容)
|
||||
- 用户传入的 config 与模板 config 合并(用户配置优先级更高)
|
||||
- total_duration 自动根据 clips 总时长计算
|
||||
"""
|
||||
from app.services import PlanGeneratorService
|
||||
|
||||
# 空串 project_id 统一为 ""
|
||||
project_id = (body.project_id or "").strip()
|
||||
# 项目鉴权
|
||||
if project_id:
|
||||
check_project_access(project_id, current_user.user.id, project_repository)
|
||||
|
||||
# 标准化用户传入的 config
|
||||
normalized_config = normalize_plan_config(body.config or {})
|
||||
|
||||
template_svc = EditTemplateService(db)
|
||||
svc = EditPlanService(db)
|
||||
# 标准化 config,填充 cover/title/subtitle/bgm 默认值
|
||||
normalized_config = normalize_plan_config(body.config)
|
||||
|
||||
# 尝试从模板生成(模板不存在时降级为空计划)
|
||||
template = None
|
||||
clips = []
|
||||
try:
|
||||
created = svc.create_plan(
|
||||
template = template_svc.get_template_or_raise(body.template_id)
|
||||
except ValueError:
|
||||
# 模板不存在,降级为普通空计划
|
||||
logger.info("模板不存在,创建空计划: template_id=%s", body.template_id)
|
||||
plan = svc.create_plan(
|
||||
template_id=body.template_id,
|
||||
name=body.name,
|
||||
config=normalized_config,
|
||||
total_duration=body.total_duration,
|
||||
project_id=project_id,
|
||||
created_by_user_id=current_user.user.id,
|
||||
total_duration=body.total_duration if body.total_duration > 0 else 0.0,
|
||||
)
|
||||
logger.info(
|
||||
"创建空剪辑计划: id=%s name=%s by user=%s",
|
||||
plan.id,
|
||||
plan.name,
|
||||
current_user.user.id,
|
||||
)
|
||||
return _to_response(plan)
|
||||
|
||||
# 模板存在,从模板生成计划+片段
|
||||
clip_configs = template_svc.list_clip_configs(body.template_id, skip=0, limit=200)
|
||||
|
||||
generator = PlanGeneratorService(db)
|
||||
try:
|
||||
result = generator.generate_from_template(
|
||||
template=template,
|
||||
clip_configs=clip_configs,
|
||||
asset_ids=[],
|
||||
project_id=project_id,
|
||||
created_by_user_id=current_user.user.id,
|
||||
name=body.name,
|
||||
)
|
||||
except ValueError as exc:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=str(exc),
|
||||
) from exc
|
||||
|
||||
plan = result["plan"]
|
||||
clips = result["clips"]
|
||||
|
||||
# 如果用户传入了自定义 config,合并覆盖模板配置
|
||||
if body.config:
|
||||
base_config = template.config or {}
|
||||
merged_config = {**base_config, **normalized_config}
|
||||
# 重新标准化确保默认值填充正确
|
||||
merged_config = normalize_plan_config(merged_config)
|
||||
plan = svc.update_plan(
|
||||
plan.id,
|
||||
config=merged_config,
|
||||
total_duration=body.total_duration if body.total_duration > 0 else None,
|
||||
)
|
||||
|
||||
logger.info(
|
||||
"创建剪辑计划: id=%s name=%s by user=%s",
|
||||
created.id,
|
||||
created.name,
|
||||
"创建剪辑计划: id=%s name=%s clips=%d by user=%s",
|
||||
plan.id,
|
||||
plan.name,
|
||||
len(clips),
|
||||
current_user.user.id,
|
||||
)
|
||||
return _to_response(created)
|
||||
return _to_response(plan)
|
||||
|
||||
|
||||
@router.put("/{plan_id}", response_model=EditPlanResponse)
|
||||
|
||||
Reference in New Issue
Block a user