feat: 新增 PDF 转换服务(epub->pdf,cookie 用户隔离,软删/硬删两级删除)
纯 Python 转换(ebooklib 解析 epub + weasyprint 渲染 HTML/CSS 为 PDF), 无需 calibre/xvfb 系统依赖。复用 UploadedFile 存储(原始文件与产物 PDF)。 - model/dao/schema:PdfJob 记录转换任务(owner_cookie/source/output/进度/状态) - pdf_converter:epub->PDF 转换器(按 spine 顺序拼 HTML,OPF 目录解析相对资源) - pdf_service:上传落盘 + asyncio 后台转换(独立 Session)+ 进度追踪 + 两级删除 · 用户软删(user_deleted,管理页仍可见)· 管理员硬删(真正删磁盘+记录) - pdf_controller:/api/pdf/*(用户,cookie)+ /api/admin/pdf/*(Basic Auth) - /pdf、/pdf-admin 页面(原生 JS,复用 common.css/js) - 配置 pdf 段(max_size 250MB、转换超时、cookie) - pytest 7 项(SQLite→MySQL 隔离测试库):上传/转换/下载/软删/硬删/超限/越权
This commit is contained in:
44
app/schemas/pdf.py
Normal file
44
app/schemas/pdf.py
Normal file
@@ -0,0 +1,44 @@
|
||||
"""PDF 转换接口 DTO。"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class PdfJobOut(BaseModel):
|
||||
"""任务对外视图(用户与管理页共用,user_deleted 仅管理页关注)。"""
|
||||
|
||||
id: int
|
||||
source_filename: str = Field(..., description="原始上传文件名")
|
||||
source_size: int = Field(..., description="原始文件字节数")
|
||||
status: str = Field(..., description="pending / converting / done / failed")
|
||||
progress: int = Field(0, description="转换进度 0-100")
|
||||
error_message: str = Field("", description="失败原因")
|
||||
user_deleted: bool = Field(False, description="用户是否已软删(管理页用)")
|
||||
deleted_at: datetime | None = Field(None, description="用户软删时间(管理页用)")
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
model_config = {"from_attributes": True}
|
||||
|
||||
|
||||
class PdfJobListResponse(BaseModel):
|
||||
"""任务列表响应。"""
|
||||
|
||||
total: int
|
||||
items: list[PdfJobOut]
|
||||
|
||||
|
||||
class PdfSubmitResponse(BaseModel):
|
||||
"""提交转换任务的响应。"""
|
||||
|
||||
job: PdfJobOut = Field(..., description="新建的任务")
|
||||
set_cookie: bool = Field(
|
||||
False, description="true=本次请求未带 cookie,响应已下发新 cookie"
|
||||
)
|
||||
|
||||
|
||||
class DeleteResult(BaseModel):
|
||||
deleted: bool
|
||||
Reference in New Issue
Block a user