"""任务与分片上传接口 DTO。""" from __future__ import annotations from datetime import datetime from pydantic import BaseModel, Field # ---------------- 分片上传(对齐 server 的协议) ---------------- class CreateSessionRequest(BaseModel): """创建一个分片上传会话。""" filename: str = Field(..., description="客户端原始文件名") size_bytes: int = Field(..., ge=0, description="文件总字节数") chunk_size: int = Field(..., gt=0, description="分片大小(字节)") total_chunks: int = Field(..., gt=0, description="分片总数") class CreateSessionResponse(BaseModel): upload_id: str filename: str size_bytes: int chunk_size: int total_chunks: int class SessionStatusResponse(BaseModel): upload_id: str filename: str size_bytes: int chunk_size: int total_chunks: int uploaded_chunks: list[int] completed: bool task_id: int | None = Field(None, description="completed=true 时指向 Task.id") class ChunkUploadResponse(BaseModel): upload_id: str index: int uploaded_chunks: list[int] class CompleteResponse(BaseModel): """complete 的回执:创建出转写任务,返回 task_id。""" task_id: int filename: str size_bytes: int status: str # ---------------- 任务查询 ---------------- class TaskResponse(BaseModel): id: int filename: str status: str progress: float error: str | None created_at: datetime updated_at: datetime class TaskListResponse(BaseModel): tasks: list[TaskResponse] total: int