技能页面改用符号链接发布,不再每会话复制

core 的 /app 静态托管已放行指向技能根目录的链接,两个技能改成链过去:
- document-photo-to-pdf:.app/doc-review/index.html 链到 web/index.html,缩略图仍写实目录;
- data-page:*.html 与 base.css 链到 templates/,config-*.js 仍是每会话实体文件。
旧会话里的实体副本会在下次发布时自动替换;模板改动从此对所有会话即时生效。
This commit is contained in:
2026-10-24 07:46:13 +08:00
parent 13b493eada
commit ab67400174
4 changed files with 59 additions and 20 deletions
+5 -4
View File
@@ -14,20 +14,21 @@ skills/document-photo-to-pdf/
run.py ← 入口
doc_deskew/ ← 检测/几何/出页/检验
review_store.py ← data.db 的 doc_review_* 表
review_page.py ← 模板副本 + 缩略图发布
review_page.py ← 模板链接 + 缩略图发布
web/index.html ← 审核页模板的单一事实源
tasks/<session-id>/
.app/doc-review/
index.html ← 每次发布覆盖的模板副本(不含数据注入)
index.html ← 指向 web/index.html 的符号链接(不含数据注入)
<batch_id>/p1.jpg ... ← 本批缩略图(长边 1200,JPEG)
data.db ← doc_review_batch / doc_review_page / doc_review_job
<output>.pdf
<output>.state.json ← state v2,供恢复自动/调试
```
core 只托管会话 `.app/`,不托管 skill 目录,所以模板必须复制一份到会话;源仍只有
`web/index.html` 一份,副本不是第二份源码。
core 只托管会话 `.app/`,不托管 skill 目录,所以会话里要有一个入口文件;用符号链接而不是
副本——源仍只有 `web/index.html` 一份,改模板即刻对所有会话生效。`/app` 静态托管会
realpath,只放行落在会话目录或技能根目录内的链接(其余 404,防止链接把 config.yml 带出来)。
## 对 AI 隐藏的参数
@@ -1,10 +1,10 @@
# -*- coding: utf-8 -*-
"""审核页发布:模板副本 + 每批缩略图,落会话 .app/doc-review/。
"""审核页发布:模板链接 + 每批缩略图,落会话 .app/doc-review/。
模板的单一事实源在 skill 目录的 web/;会话里的 index.html 只是发布副本,
不含任何数据注入。页面运行时通过 /api/db 读 doc_review_* 表,因此同一份
HTML 可服务所有批次。core 只托管会话 .app/,不托管 skill 目录,这是必须
复制一次的原因(不是第二份源码)。
模板的单一事实源在 skill 目录的 web/;会话里的 index.html 只是指向它的符号链接,
不含任何数据注入。core 的 /app 静态托管放行指向技能根目录的链接(其余位置 404),
所以改一次模板就对所有会话生效,不用重新生成。页面运行时通过 /api/db 读 doc_review_*
表,因此同一份 HTML 可服务所有批次。缩略图是每会话的数据,仍写真目录。
"""
import os
import shutil
@@ -17,6 +17,25 @@ THUMB_LONG = 1200
THUMB_Q = 80
def _link(src, dst):
"""把技能里的静态文件以符号链接发布到会话目录。
旧版本是复制副本,模板改动到不了已有会话;改链接后技能就是唯一真源。
链接目标用绝对路径:executor 与 core 都把技能挂在同一位置,两边都能解析。
"""
src = os.path.abspath(src)
if os.path.islink(dst):
try:
if os.path.realpath(dst) == os.path.realpath(src):
return
except OSError:
pass
os.unlink(dst)
elif os.path.exists(dst):
os.unlink(dst) # 旧会话的实体副本:删掉换成链接
os.symlink(src, dst)
def publish(session_root, batch_id, pages):
"""发布模板与缩略图。
@@ -27,7 +46,7 @@ def publish(session_root, batch_id, pages):
for name in sorted(os.listdir(WEB_DIR)):
src = os.path.join(WEB_DIR, name)
if os.path.isfile(src):
shutil.copy2(src, os.path.join(app_dir, name))
_link(src, os.path.join(app_dir, name))
thumb_dir = os.path.join(app_dir, batch_id)
os.makedirs(thumb_dir, exist_ok=True)