c243c4dd58
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 1s
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 4s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 58s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 59s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m15s
CI/CD Pipeline / Unit Tests (pull_request) Failing after 3m3s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 2m49s
CI/CD Pipeline / Validate - Style (pull_request) Successful in 3m36s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 2m52s
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Successful in 6m11s
AI Code Review / AI Code Review (pull_request) Successful in 6m29s
CI/CD Pipeline / Validate - Security (pull_request) Successful in 9m48s
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / CI Gate (pull_request) Failing after 2s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 6m14s
CI/CD Pipeline / Build Production Worker Image (pull_request) Failing after 28h58m29s
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Failing after 29h7m28s
CI/CD Pipeline / PR Build Web Image (pull_request) Failing after 29h8m27s
CI/CD Pipeline / Build Staging Worker Image (pull_request) Failing after 29h7m47s
CI/CD Pipeline / Build Staging Web Image (pull_request) Failing after 29h7m47s
CI/CD Pipeline / Build Staging API Image (pull_request) Failing after 29h7m48s
CI/CD Pipeline / Check push changed paths (pull_request) Failing after 29h7m53s
CI/CD Pipeline / Deploy Production (pull_request) Failing after 28h57m51s
CI/CD Pipeline / Build Production Web Image (pull_request) Failing after 28h57m52s
CI/CD Pipeline / Build Production API Image (pull_request) Failing after 28h57m52s
CI/CD Pipeline / ACR Image Cleanup (pull_request) Failing after 29h6m40s
CI/CD Pipeline / Canary Release to Production (pull_request) Failing after 28h57m50s
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Failing after 29h6m51s
CI/CD Pipeline / Frontend Lint (pull_request) Failing after 29h7m11s
CI/CD Pipeline / Staging API Integration Tests (pull_request) Failing after 29h6m40s
CI/CD Pipeline / Staging E2E Tests (pull_request) Failing after 29h6m40s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Failing after 29h6m46s
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Failing after 29h6m51s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 29h7m10s
67 lines
2.5 KiB
Python
67 lines
2.5 KiB
Python
"""P0 fix: 共享的默认模板自动兜底逻辑。"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
from typing import Optional
|
|
|
|
from sqlalchemy.orm import Session
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def get_or_create_default_template_id(db: Session, user_id: str) -> Optional[str]:
|
|
"""为用户查找一个有效模板;若不存在则自动创建默认配音模板。"""
|
|
from packages.adapters.sqlalchemy_impl.models import TemplateClipConfigModel, TemplateModel
|
|
from packages.adapters.sqlalchemy_impl.template_repository import SQLAlchemyTemplateRepository
|
|
from packages.application.template.commands import CreateTemplateCommand, SegmentCommand
|
|
from packages.application.template.use_cases import CreateTemplateUseCase
|
|
|
|
existing = (
|
|
db.query(TemplateModel)
|
|
.filter(TemplateModel.user_id == user_id, TemplateModel.is_active.is_(True))
|
|
.order_by(TemplateModel.created_at.asc())
|
|
.first()
|
|
)
|
|
if existing is not None:
|
|
has_seg = (
|
|
db.query(TemplateClipConfigModel.id).filter(TemplateClipConfigModel.template_id == existing.id).first()
|
|
)
|
|
if has_seg:
|
|
return existing.id
|
|
|
|
try:
|
|
repo = SQLAlchemyTemplateRepository(db)
|
|
cmd = CreateTemplateCommand(
|
|
user_id=user_id,
|
|
name="默认配音模板",
|
|
mode="voice_over",
|
|
category="default",
|
|
tags=[],
|
|
title_config={},
|
|
subtitle_config={},
|
|
bgm_config={},
|
|
estimated_duration=0.0,
|
|
segments=[SegmentCommand(segment_order=0, duration_min=1.0, duration_max=30.0)],
|
|
)
|
|
tpl = CreateTemplateUseCase(repo).execute(cmd)
|
|
db.commit()
|
|
logger.info("[default-template] 自动创建默认模板: user=%s tpl=%s", user_id, tpl.id)
|
|
return tpl.id
|
|
except Exception:
|
|
db.rollback()
|
|
existing2 = (
|
|
db.query(TemplateModel)
|
|
.filter(TemplateModel.user_id == user_id, TemplateModel.is_active.is_(True))
|
|
.order_by(TemplateModel.created_at.asc())
|
|
.first()
|
|
)
|
|
if existing2 is not None:
|
|
has_seg2 = (
|
|
db.query(TemplateClipConfigModel.id).filter(TemplateClipConfigModel.template_id == existing2.id).first()
|
|
)
|
|
if has_seg2:
|
|
return existing2.id
|
|
logger.exception("[default-template] 自动创建默认模板失败: user=%s", user_id)
|
|
return None
|