649420bd35
CI/CD Pipeline / Check push changed paths (pull_request) Has been skipped
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 2s
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 1m12s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 1m21s
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 1m29s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 2m0s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Successful in 2m10s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 2m18s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m13s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 3m42s
AI Code Review / AI Code Review (pull_request) Successful in 6m41s
CI/CD Pipeline / Build Production API Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Web Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Deploy Production (pull_request) Has been cancelled
CI/CD Pipeline / Production Browser E2E (pull_request) Has been cancelled
CI/CD Pipeline / Canary Release to Production (pull_request) Has been cancelled
CI/CD Pipeline / CI Gate (pull_request) Has been cancelled
CI/CD Pipeline / Validate - Style (pull_request) Has been cancelled
CI/CD Pipeline / Validate - Security (pull_request) Has been cancelled
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Has been cancelled
CI/CD Pipeline / Unit Tests (pull_request) Has been cancelled
PR Automation / Auto Merge on CI Green + Approved (pull_request) Has been cancelled
- 输出从营销口播文案改为专业编导分镜脚本(CopyResult v1.6:overview/scene_and_lighting/shots/hard_constraints/negative_prompts/voiceover_script) - 新 SCRIPT_GENERATION 阶段替代原 copy_fusion+storyboard+review,prompt 指导 LLM 输出严格 JSON 结构 - pipeline 简化为4步:图片分析 → 编导脚本 → TTS整段合成(上传OSS做reference_audios) → 单次Seedance出片 → 上传 - 删除:多段分镜拆分、ffmpeg concat拼接、placeholder占位视频、分段重试降级、BGM单独混音(Seedance generate_audio=true原生合成音效/BGM) - ai_client/ai_service video_generation 支持 reference_images/reference_audios/reference_videos/generate_audio 参数 - duration 默认15秒,上限30秒;前端时长下拉 5/10/15/20/25/30s - 首帧图模式不传 ratio(保持 #2110 修复) - Alembic migration 088 幂等添加 voice_id/voice_source/video_ratio/video_model/copy_result 五列 - _step_image_analysis call_vision() 全路径 None 防护 - 向后兼容:final_copy=voiceover_script、storyboard=shots、老数据 _build_copy_result 降级拼装 - TS types 更新 CopyResult v1.6 结构 + ShotScript/Overview - 96个 viral 相关单测全通过
240 lines
9.3 KiB
Python
Executable File
240 lines
9.3 KiB
Python
Executable File
"""爆款视频任务 SQLAlchemy 仓储实现。"""
|
|
|
|
from datetime import datetime, timezone
|
|
|
|
from sqlalchemy.orm import Session
|
|
|
|
from packages.adapters.sqlalchemy_impl.models import (
|
|
ViralVideoJobModel,
|
|
ViralVideoPromptTemplateModel,
|
|
ViralVideoStyleTemplateModel,
|
|
)
|
|
from packages.domain.viral_video import ViralVideoJob, ViralVideoStatus
|
|
|
|
|
|
def _to_domain(model: ViralVideoJobModel) -> ViralVideoJob:
|
|
"""ORM → 领域实体。"""
|
|
return ViralVideoJob(
|
|
id=model.id,
|
|
user_id=model.user_id,
|
|
images=list(model.images or []),
|
|
industry=model.industry or "",
|
|
target_customer=model.target_customer or "",
|
|
persona_id=model.persona_id or "",
|
|
viral_structure=model.viral_structure or "",
|
|
marketing_purpose=model.marketing_purpose or "",
|
|
bgm_preference=model.bgm_preference or "",
|
|
duration=model.duration or 15,
|
|
user_copy_text=model.user_copy_text or "",
|
|
fusion_level=model.fusion_level or "ai_polish",
|
|
reference_audio_path=model.reference_audio_path or "",
|
|
reference_video_url=getattr(model, "reference_video_url", "") or "",
|
|
style_strength=getattr(model, "style_strength", "medium") or "medium",
|
|
style_guide=dict(model.style_guide) if model.style_guide else None,
|
|
style_template_id=getattr(model, "style_template_id", "") or "",
|
|
voice_id=getattr(model, "voice_id", "") or "",
|
|
voice_source=getattr(model, "voice_source", "") or "",
|
|
video_ratio=getattr(model, "video_ratio", "9:16") or "9:16",
|
|
video_model=getattr(model, "video_model", "") or "",
|
|
status=ViralVideoStatus(model.status) if model.status else ViralVideoStatus.PENDING,
|
|
intent_result=dict(model.intent_result) if model.intent_result else None,
|
|
image_analysis=dict(model.image_analysis) if getattr(model, "image_analysis", None) else None,
|
|
storyboard=list(model.storyboard) if getattr(model, "storyboard", None) else None,
|
|
generated_copy_text=getattr(model, "generated_copy_text", "") or "",
|
|
copy_result=dict(model.copy_result) if getattr(model, "copy_result", None) else None,
|
|
result_video_url=model.result_video_url or "",
|
|
credits_cost=model.credits_cost or 0,
|
|
error_msg=model.error_msg or "",
|
|
retry_count=model.retry_count or 0,
|
|
started_at=model.started_at,
|
|
completed_at=model.completed_at,
|
|
created_at=model.created_at,
|
|
updated_at=model.updated_at,
|
|
)
|
|
|
|
|
|
class SQLAlchemyViralVideoJobRepository:
|
|
"""爆款视频任务仓储。"""
|
|
|
|
def __init__(self, session: Session):
|
|
self.session = session
|
|
|
|
def save(self, job: ViralVideoJob) -> ViralVideoJob:
|
|
model = ViralVideoJobModel(
|
|
id=job.id,
|
|
user_id=job.user_id,
|
|
images=job.images,
|
|
industry=job.industry,
|
|
target_customer=job.target_customer,
|
|
persona_id=job.persona_id,
|
|
viral_structure=job.viral_structure,
|
|
marketing_purpose=job.marketing_purpose,
|
|
bgm_preference=job.bgm_preference,
|
|
duration=job.duration,
|
|
user_copy_text=job.user_copy_text,
|
|
fusion_level=job.fusion_level,
|
|
reference_audio_path=job.reference_audio_path,
|
|
reference_video_url=job.reference_video_url,
|
|
style_strength=job.style_strength,
|
|
style_guide=job.style_guide,
|
|
style_template_id=job.style_template_id,
|
|
voice_id=job.voice_id,
|
|
voice_source=job.voice_source,
|
|
video_ratio=job.video_ratio,
|
|
video_model=job.video_model,
|
|
status=job.status,
|
|
intent_result=job.intent_result,
|
|
image_analysis=job.image_analysis,
|
|
storyboard=job.storyboard,
|
|
generated_copy_text=job.generated_copy_text,
|
|
copy_result=job.copy_result,
|
|
result_video_url=job.result_video_url,
|
|
credits_cost=job.credits_cost,
|
|
error_msg=job.error_msg,
|
|
retry_count=job.retry_count,
|
|
started_at=job.started_at,
|
|
completed_at=job.completed_at,
|
|
created_at=job.created_at,
|
|
updated_at=job.updated_at,
|
|
)
|
|
self.session.add(model)
|
|
self.session.commit()
|
|
return job
|
|
|
|
def update(self, job: ViralVideoJob) -> None:
|
|
model = self.session.query(ViralVideoJobModel).filter(ViralVideoJobModel.id == job.id).first()
|
|
if model is None:
|
|
raise ValueError(f"ViralVideoJob {job.id} not found")
|
|
model.status = job.status
|
|
model.intent_result = job.intent_result
|
|
model.image_analysis = job.image_analysis
|
|
model.storyboard = job.storyboard
|
|
model.generated_copy_text = job.generated_copy_text or ""
|
|
model.copy_result = job.copy_result
|
|
model.result_video_url = job.result_video_url
|
|
model.credits_cost = job.credits_cost
|
|
model.error_msg = job.error_msg
|
|
model.retry_count = job.retry_count
|
|
model.started_at = job.started_at
|
|
model.completed_at = job.completed_at
|
|
model.style_guide = job.style_guide
|
|
# v1.5 three-stage: persist user-editable params so resume uses latest values
|
|
model.user_copy_text = job.user_copy_text
|
|
model.industry = job.industry
|
|
model.target_customer = job.target_customer
|
|
model.persona_id = job.persona_id
|
|
model.viral_structure = job.viral_structure
|
|
model.marketing_purpose = job.marketing_purpose
|
|
model.bgm_preference = job.bgm_preference
|
|
model.duration = job.duration
|
|
model.fusion_level = job.fusion_level
|
|
model.reference_audio_path = job.reference_audio_path
|
|
model.reference_video_url = job.reference_video_url
|
|
model.style_strength = job.style_strength
|
|
model.style_template_id = job.style_template_id
|
|
model.voice_id = job.voice_id or ""
|
|
model.voice_source = job.voice_source or ""
|
|
model.video_ratio = job.video_ratio or "9:16"
|
|
model.video_model = job.video_model or ""
|
|
model.updated_at = datetime.now(timezone.utc)
|
|
self.session.commit()
|
|
|
|
def get(self, job_id: str) -> ViralVideoJob | None:
|
|
model = self.session.query(ViralVideoJobModel).filter(ViralVideoJobModel.id == job_id).first()
|
|
if model is None:
|
|
return None
|
|
return _to_domain(model)
|
|
|
|
def list_by_user(self, user_id: str, limit: int = 50, offset: int = 0) -> list[ViralVideoJob]:
|
|
models = (
|
|
self.session.query(ViralVideoJobModel)
|
|
.filter(ViralVideoJobModel.user_id == user_id)
|
|
.order_by(ViralVideoJobModel.created_at.desc())
|
|
.offset(offset)
|
|
.limit(limit)
|
|
.all()
|
|
)
|
|
return [_to_domain(m) for m in models]
|
|
|
|
def count_pending_by_user(self, user_id: str) -> int:
|
|
return (
|
|
self.session.query(ViralVideoJobModel)
|
|
.filter(
|
|
ViralVideoJobModel.user_id == user_id,
|
|
ViralVideoJobModel.status.in_(
|
|
["pending", "running", "wait_user_confirm", "image_analyzed", "copy_generated"]
|
|
),
|
|
)
|
|
.count()
|
|
)
|
|
|
|
|
|
class SQLAlchemyViralVideoStyleTemplateRepository:
|
|
"""风格模板仓储。"""
|
|
|
|
def __init__(self, session: Session):
|
|
self.session = session
|
|
|
|
def list_all(self) -> list[dict]:
|
|
models = (
|
|
self.session.query(ViralVideoStyleTemplateModel)
|
|
.order_by(ViralVideoStyleTemplateModel.sort_order.asc())
|
|
.all()
|
|
)
|
|
return [
|
|
{
|
|
"id": m.id,
|
|
"name": m.name,
|
|
"description": m.description or "",
|
|
"thumbnail_url": m.thumbnail_url or "",
|
|
"style_config": dict(m.style_config) if m.style_config else {},
|
|
"is_system": m.is_system,
|
|
}
|
|
for m in models
|
|
]
|
|
|
|
def get(self, template_id: str) -> dict | None:
|
|
model = (
|
|
self.session.query(ViralVideoStyleTemplateModel)
|
|
.filter(ViralVideoStyleTemplateModel.id == template_id)
|
|
.first()
|
|
)
|
|
if model is None:
|
|
return None
|
|
return {
|
|
"id": model.id,
|
|
"name": model.name,
|
|
"description": model.description or "",
|
|
"thumbnail_url": model.thumbnail_url or "",
|
|
"style_config": dict(model.style_config) if model.style_config else {},
|
|
"is_system": model.is_system,
|
|
}
|
|
|
|
|
|
class SQLAlchemyViralVideoPromptTemplateRepository:
|
|
"""Prompt 模板仓储(由 #2040 seed,这里只读取)。"""
|
|
|
|
def __init__(self, session: Session):
|
|
self.session = session
|
|
|
|
def get_active_by_type(self, prompt_type: str) -> dict | None:
|
|
model = (
|
|
self.session.query(ViralVideoPromptTemplateModel)
|
|
.filter(
|
|
ViralVideoPromptTemplateModel.prompt_type == prompt_type,
|
|
ViralVideoPromptTemplateModel.is_active.is_(True),
|
|
)
|
|
.order_by(ViralVideoPromptTemplateModel.version.desc())
|
|
.first()
|
|
)
|
|
if model is None:
|
|
return None
|
|
return {
|
|
"id": model.id,
|
|
"prompt_type": model.prompt_type,
|
|
"name": model.name,
|
|
"content": model.content,
|
|
"variables": list(model.variables or []),
|
|
"version": model.version,
|
|
}
|