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:
@@ -108,6 +108,24 @@ class WhiteboardConfig(BaseModel):
|
||||
list_limit: int = 100
|
||||
|
||||
|
||||
class PdfConfig(BaseModel):
|
||||
"""PDF 转换服务配置。
|
||||
|
||||
用户侧(上传/查看/下载/软删)凭 httpOnly cookie 标识;管理侧(列表/硬删)
|
||||
走 docs 同款 Basic Auth。原始文件与产物 PDF 复用 storage.upload_dir 落盘。
|
||||
"""
|
||||
|
||||
# 单文件大小上限(字节)。250 MiB。
|
||||
max_size_bytes: int = 250 * 1024 * 1024
|
||||
# 转换超时(秒):超大/复杂文件兜底,避免长期占用 worker。
|
||||
convert_timeout_seconds: int = 600
|
||||
# 列表分页默认值
|
||||
list_limit: int = 100
|
||||
# 用户 cookie 名与有效期
|
||||
cookie_name: str = "zk_pdf"
|
||||
cookie_max_age_seconds: int = 365 * 24 * 3600
|
||||
|
||||
|
||||
class Settings(BaseModel):
|
||||
server: ServerConfig = ServerConfig()
|
||||
database: DatabaseConfig = DatabaseConfig()
|
||||
@@ -116,6 +134,7 @@ class Settings(BaseModel):
|
||||
docs: DocsConfig = DocsConfig()
|
||||
tunnel: TunnelConfig = TunnelConfig()
|
||||
whiteboard: WhiteboardConfig = WhiteboardConfig()
|
||||
pdf: PdfConfig = PdfConfig()
|
||||
|
||||
def db_url(self) -> str:
|
||||
c = self.database
|
||||
|
||||
Reference in New Issue
Block a user