"""分片上传接口 DTO。""" from __future__ import annotations from pydantic import BaseModel, Field 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 = Field(..., description="服务端生成的会话标识,后续接口都需要它") 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] = Field(..., description="已上传的分片下标集合") completed: bool = Field(..., description="是否已完成拼接入库") file_id: int | None = Field(None, description="completed=true 时指向 UploadedFile.id") class ChunkUploadResponse(BaseModel): """单个分片上传成功的回执。""" upload_id: str index: int uploaded_chunks: list[int]