1. 合并 files-page 与 pdf-admin 为统一文件管理页 /api/files-page:
- 新增 GET /api/admin/files/with-pdf 接口,以 uploaded_files 为基础,
用 pdf_jobs.source_file_id / output_file_id 内存匹配,为关联文件标注
转换状态、用户软删标记与角色(源epub/产物PDF)
- PdfJobOut 补 source_file_id / output_file_id 字段
- file_browser 新增 PDF 任务列(状态徽标/软删标记/硬删任务按钮)
- 删除 /api/pdf-admin 路由及 static/pdf_admin.* 三个文件
2. 新增导航页 /api/index,卡片式收集所有页面入口;
各子页(upload/whiteboard/system_status/files-page)脚注加返回导航链接
3. 更新 docs/routes.md、docs/configuration.md 同步说明
测试: pytest tests/test_pdf_service.py 7 passed; 手动校验各页面路由与合并接口响应
67 lines
2.0 KiB
Python
67 lines
2.0 KiB
Python
"""文件接口 DTO。"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
class UploadedFileOut(BaseModel):
|
|
id: int
|
|
storage_path: str
|
|
original_filename: str
|
|
content_type: str
|
|
size_bytes: int
|
|
sha256: str
|
|
source: str
|
|
uploaded_by: str
|
|
uploaded_at: datetime
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
class FileUploadResponse(BaseModel):
|
|
id: int = Field(..., description="新写入的数据库行 ID")
|
|
filename: str = Field(..., description="客户端原始文件名")
|
|
size_bytes: int
|
|
sha256: str
|
|
storage_path: str
|
|
uploaded_at: datetime
|
|
deduplicated: bool = Field(
|
|
False, description="true=服务端已有同 sha256 文件,直接返回旧行,未重复落盘"
|
|
)
|
|
|
|
|
|
class FileListResponse(BaseModel):
|
|
total: int
|
|
items: list[UploadedFileOut]
|
|
|
|
|
|
class PdfJobBrief(BaseModel):
|
|
"""文件关联到的 PDF 转换任务摘要(供合并管理页展示)。
|
|
|
|
一个 uploaded_file 可能同时被多个 job 引用(罕见),故为列表;
|
|
通常每行 0 或 1 条。
|
|
"""
|
|
|
|
job_id: int
|
|
role: str = Field(..., description='"source"=该文件是 epub 源文件;"output"=该文件是产物 PDF')
|
|
status: str = Field(..., description="pending / converting / done / failed")
|
|
progress: int = Field(0, description="转换进度 0-100")
|
|
user_deleted: bool = Field(False, description="用户是否已软删该任务")
|
|
deleted_at: datetime | None = Field(None, description="用户软删时间")
|
|
|
|
|
|
class UploadedFileWithPdfOut(UploadedFileOut):
|
|
"""带 PDF 任务关联信息的文件视图(合并管理页用)。"""
|
|
|
|
pdf_jobs: list[PdfJobBrief] = Field(default_factory=list, description="关联到的 PDF 转换任务")
|
|
|
|
|
|
class FileWithPdfListResponse(BaseModel):
|
|
"""合并管理页列表响应:以 uploaded_files 为基础,附带 pdf_jobs 关联。"""
|
|
|
|
total: int
|
|
items: list[UploadedFileWithPdfOut]
|