From 9985f7c81af3d18f3e3f165d3a877370fca58c10 Mon Sep 17 00:00:00 2001 From: kinghwj Date: Tue, 20 Oct 2026 15:06:54 +0800 Subject: [PATCH] =?UTF-8?q?feat(version):=20=E6=98=BE=E7=A4=BA=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E7=89=88=E6=9C=AC=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 ++ VERSION | 1 + app.py | 11 +++++++++++ docs/code-design.md | 4 ++++ docs/technical-guide.md | 2 ++ templates/index.html | 8 ++++++-- templates/login.html | 4 ++-- tests/test_auth.py | 1 + 8 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 VERSION diff --git a/README.md b/README.md index 21f1208..184876a 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,8 @@ DEPLOY_BRANCH=master ./deploy.sh 运行端口、Python 环境、HTTPS 证书和接口故障的诊断方法见 [日常维护与故障排查](docs/troubleshooting.md)。 +当前应用版本保存在根目录 `VERSION`,网页底部和登录页会显示该版本号。 + ## 功能模块 | 模块 | 说明 | diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..085135e --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +v0.1 diff --git a/app.py b/app.py index 24e6f16..ce02e9d 100644 --- a/app.py +++ b/app.py @@ -25,6 +25,7 @@ import time import urllib.request from datetime import datetime from functools import wraps +from pathlib import Path import pymysql @@ -45,6 +46,16 @@ from reading_api import reading_bp # ====================================================================== app = Flask(__name__, static_folder="static", template_folder="templates") +try: + APP_VERSION = Path(__file__).with_name("VERSION").read_text(encoding="utf-8").strip() +except FileNotFoundError: + APP_VERSION = "unknown" + + +@app.context_processor +def inject_app_version(): + return {"app_version": APP_VERSION} + # 注册当前看板数据接口,并保留旧客户端兼容路径。 app.register_blueprint(reading_bp) register_auth(app) diff --git a/docs/code-design.md b/docs/code-design.md index 2a79267..da94eac 100644 --- a/docs/code-design.md +++ b/docs/code-design.md @@ -63,6 +63,10 @@ GitHub Actions 的 `.github/workflows/deploy.yml` 只做验证,不登录服务 例:正式域名为 `laohang.space`、备案号为 `浙ICP备202607916号-1`,首页页脚显示该备案号;点击后打开 `https://beian.miit.gov.cn/`。截图里的公安联网备案数据码不是公安备案号,不作为备案号码展示。 +## 应用版本显示 + +根目录 `VERSION` 保存面向用户的版本号,例如输入 `v0.1`,Flask 在启动时读取并通过模板上下文注入 `app_version`。首页页脚和登录页显示“版本 v0.1”。版本号不包含分支名或提交号;发布新版本时修改 `VERSION` 后随 `master` 一起部署。 + 应用未内置登录尝试限流;公网部署应在可信反向代理上为 `POST /auth/login` 设置频率限制,且不要直接信任未校验的 `X-Forwarded-For`。 ## 示例与真实接口的边界 diff --git a/docs/technical-guide.md b/docs/technical-guide.md index c5a5d94..51cceac 100644 --- a/docs/technical-guide.md +++ b/docs/technical-guide.md @@ -138,6 +138,8 @@ DEPLOY_BRANCH=master ./deploy.sh 正式网站域名 `laohang.space` 的页脚展示工信部 ICP 备案号 `浙ICP备202607916号-1`,点击后跳转至工信部备案查询平台。公安联网备案数据码不是公安备案号,因此不在页脚作为公安备案信息展示。 +网站页脚和登录页显示版本文件 `VERSION` 的内容,例如 `v0.1`。发布新版本时修改该文件并随代码合并到 `master`;部署后可直接在网页底部确认当前应用版本。 + 保存失败会保留表单并提示重试;读取失败显示错误和重试按钮,不冒充空列表。若新建提示 ID 已存在,刷新目标列表确认上次请求是否已经保存。数据库不可用或尚未执行迁移时,目标接口返回 503,不退回浏览器保存。 验证命令: diff --git a/templates/index.html b/templates/index.html index 00311f3..9b38c7e 100644 --- a/templates/index.html +++ b/templates/index.html @@ -19,6 +19,10 @@ gap: 12px } + .app-version { + white-space: nowrap + } + .icp-link { color: inherit; text-decoration: none @@ -123,7 +127,7 @@ id="conn-state">正在连接微信读书…阅读目标跨浏览器保存
@@ -162,4 +166,4 @@ - \ No newline at end of file + diff --git a/templates/login.html b/templates/login.html index f25f288..8c58c92 100644 --- a/templates/login.html +++ b/templates/login.html @@ -42,8 +42,8 @@ {% endif %} -

阅间 · 与好书相伴,与自己相遇

+

阅间 · 与好书相伴,与自己相遇 · 版本 {{ app_version }}

- \ No newline at end of file + diff --git a/tests/test_auth.py b/tests/test_auth.py index 9cf74b1..7fa33cf 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -92,6 +92,7 @@ class AuthTests(unittest.TestCase): self.assertEqual(response.status_code, 200) self.assertIn(b"https://beian.miit.gov.cn/", response.data) self.assertIn("浙ICP备202607916号-1".encode(), response.data) + self.assertIn("版本 v0.1".encode(), response.data) def test_first_account_requires_setup_token_and_is_stored_as_hash(self): page = self.client.get("/login")