9652e9e892
CI/CD Pipeline / Check if frontend-only change (push) Has been cancelled
CI/CD Pipeline / Validate - Code Quality (push) Has been cancelled
CI/CD Pipeline / Validate - Type Check (mypy) (push) Has been cancelled
CI/CD Pipeline / Validate - Migration (alembic) (push) Has been cancelled
CI/CD Pipeline / Unit Tests (push) Has been cancelled
CI/CD Pipeline / Integration Tests (push) Has been cancelled
CI/CD Pipeline / Frontend Lint (push) Has been cancelled
CI/CD Pipeline / Frontend Unit Tests (push) Has been cancelled
CI/CD Pipeline / PR Build API Image (push) Has been cancelled
CI/CD Pipeline / PR Build Web Image (push) Has been cancelled
CI/CD Pipeline / PR Build Worker Image (push) Has been cancelled
CI/CD Pipeline / Build Staging API Image (push) Has been cancelled
CI/CD Pipeline / Build Staging Web Image (push) Has been cancelled
CI/CD Pipeline / Build Staging Worker Image (push) Has been cancelled
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Has been cancelled
CI/CD Pipeline / Staging E2E Tests (push) Has been cancelled
CI/CD Pipeline / Staging API Integration Tests (push) Has been cancelled
CI/CD Pipeline / Build Production API Image (push) Has been cancelled
CI/CD Pipeline / Build Production Web Image (push) Has been cancelled
CI/CD Pipeline / Build Production Worker Image (push) Has been cancelled
CI/CD Pipeline / Deploy Production (push) Has been cancelled
CI/CD Pipeline / Production Browser E2E (push) Has been cancelled
CI/CD Pipeline / ACR Image Cleanup (push) Has been cancelled
62 lines
2.0 KiB
Python
Executable File
62 lines
2.0 KiB
Python
Executable File
"""时间线路由.
|
|
|
|
端点:
|
|
- GET /timeline 时间线场景数据
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from app.auth import AuthenticatedUser, get_current_user
|
|
from app.services.edit_plan_service import EditPlanService
|
|
from app.services.edit_template_service import EditTemplateService
|
|
from fastapi import APIRouter, Depends
|
|
|
|
from ._utils import _CLIP_TYPE_COLORS, _DEFAULT_COLOR, _clip_type_to_scene_label, _format_time
|
|
from .dependencies import get_draft_plan_id, get_editor_services
|
|
from .schemas import EditorTimelineResponse, EditorTimelineSceneResponse
|
|
|
|
router = APIRouter(tags=["Template Editor"])
|
|
|
|
|
|
@router.get("/timeline", response_model=EditorTimelineResponse)
|
|
def get_editor_timeline(
|
|
template_id: str,
|
|
plan_id: str = Depends(get_draft_plan_id),
|
|
services: tuple[EditTemplateService, EditPlanService] = Depends(get_editor_services),
|
|
_: AuthenticatedUser = Depends(get_current_user),
|
|
) -> EditorTimelineResponse:
|
|
"""获取草稿的时间线场景数据"""
|
|
_, plan_svc = services
|
|
plan = plan_svc.get_plan_or_raise(plan_id)
|
|
clips = plan_svc.list_clips(plan_id=plan_id, skip=0, limit=200)
|
|
clips.sort(key=lambda c: c.order)
|
|
|
|
scenes = []
|
|
current_time = 0.0
|
|
|
|
for clip in clips:
|
|
start = current_time
|
|
end = start + clip.duration
|
|
color = _CLIP_TYPE_COLORS.get(clip.clip_type, _DEFAULT_COLOR)
|
|
scene_label = _clip_type_to_scene_label(clip.clip_type, clip.text_content)
|
|
|
|
scenes.append(
|
|
EditorTimelineSceneResponse(
|
|
scene=scene_label,
|
|
time=f"{_format_time(start)} - {_format_time(end)}",
|
|
duration=clip.duration,
|
|
color=color,
|
|
clip_id=clip.id,
|
|
clip_type=clip.clip_type,
|
|
)
|
|
)
|
|
current_time = end
|
|
|
|
total_duration = sum(s.duration for s in scenes) or plan.total_duration
|
|
|
|
return EditorTimelineResponse(
|
|
plan_id=plan_id,
|
|
total_duration=total_duration,
|
|
scenes=scenes,
|
|
)
|