Files
zTools2/config.example.yaml
zikai aa08a1cf60 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 隔离测试库):上传/转换/下载/软删/硬删/超限/越权
2026-07-27 11:33:43 +08:00

77 lines
3.8 KiB
YAML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Application runtime configuration. Copy from config.example.yaml and fill in real values.
# All secrets (DB password, SFTP user hashes/keys) live here - keep it out of version control.
server:
host: 127.0.0.1 # bind address; Apache proxies f.zikai.wang -> here
port: 6867 # internal port; MUST match the Apache ProxyPass target
workers: 1 # uvicorn worker count
database:
host: 127.0.0.1
port: 3306
user: zikai_filesvc
password: "CHANGE_ME" # generated/overwritten by setup.sh provisioning
database: zikai_filesvc # independent new database (not shared with other apps)
pool_size: 5
pool_recycle: 1800
storage:
upload_dir: ./uploads # where uploaded files are written (shared with SFTP)
chunk_bytes: 1048576 # 1 MiB streaming chunk for HTTP upload (keeps RAM flat)
sha256_on_upload: true # compute sha256 while streaming to disk
chunk_session_dir: ./.work # 分片上传会话暂存目录(相对 upload_dir拼接在此完成
chunk_session_ttl_seconds: 300 # 被放弃会话的存活秒数;后台 reaper 据此清理临时文件
sftp:
enabled: true
host: 0.0.0.0 # SFTP cannot go through Apache's HTTP proxy, expose directly
port: 2022 # open this port in the firewall for external SFTP clients
host_key_path: ./keys/ssh_host_ed25519_key
authorized_keys_path: ./keys/authorized_keys
# Each user may authenticate by password (bcrypt hash) and/or by a public key listed
# in authorized_keys_path. Generate a bcrypt hash with:
# python -c "import bcrypt;print(bcrypt.hashpw(b'yourpass',bcrypt.gensalt()).decode())"
users:
- username: uploader
password_hash: "CHANGE_ME_BCRYPT_HASH"
# public keys for this user go in keys/authorized_keys (one key per line, OpenSSH format)
docs:
# /docs, /redoc and /openapi.json are protected with HTTP Basic Auth.
# Password is stored as plaintext here -- this file is root-owned and lives
# only on this server; comparison is constant-time. No hashing needed.
enabled: true
username: admin
password: "CHANGE_ME"
realm: "zikai docs"
tunnel:
# 反向隧道user 端通过 SSH 反向转发把本地服务暴露到 serverserver 再经
# HTTP 路由 /api/userPort/{userName} 对公网提供访问。disabled 时 SSH 拒绝转发请求。
enabled: false
users:
- username: tunneluser
password_hash: "CHANGE_ME_BCRYPT_HASH" # bcrypt生成方式同 sftp.users
tunnel_port: 9001 # server 侧 SSH remote forward 绑定的本地端口
local_port: 8080 # user 端要暴露的本地服务端口(仅记录用)
whiteboard:
# 共享白板:/whiteboard/{id} 公开访问并实时协作WebSocket管理页 /whiteboard-admin
# 与 /api/admin/whiteboards 走 docs 同款 Basic Auth。
# 心跳:客户端每 heartbeat_interval_seconds 发一次 ping连续丢失 heartbeat_miss_threshold
# 次判失活,服务端关闭并移除该连接。
heartbeat_interval_seconds: 3
heartbeat_miss_threshold: 5
max_board_id_length: 64 # board_id 合法字符 [a-zA-Z0-9_-],长度上限
list_limit: 100 # 管理页单次列表上限
pdf:
# PDF 转换服务:用户上传 epub -> 后台转换为 PDF -> 显示进度并下载。
# 用户侧(上传/查看/下载/软删)凭 httpOnly cookie 标识;管理侧(列表/硬删)走 docs 同款 Basic Auth。
# 原始文件与产物 PDF 复用 storage.upload_dir 落盘。转换用纯 Pythonebooklib + weasyprint
max_size_bytes: 262144000 # 单文件上限 250 MiB
convert_timeout_seconds: 600 # 转换超时(秒),超大文件兜底
list_limit: 100 # 列表单次上限
cookie_name: zk_pdf # 用户标识 cookie 名
cookie_max_age_seconds: 31536000 # cookie 有效期 1 年