修复登记借出按钮并更新前端缓存版本

This commit is contained in:
2026-11-17 14:35:12 +08:00
parent 05d212ac83
commit 5b3dd674de
3 changed files with 21 additions and 4 deletions
+10
View File
@@ -808,6 +808,16 @@ async def security_headers(request: Request, call_next):
)
if request.url.path.startswith(("/api/", "/join/", "/duty-confirm/", "/mail-test/")):
response.headers["Cache-Control"] = "no-store"
elif request.method in ("GET", "HEAD") and (
request.url.path == "/"
or request.url.path.endswith(".html")
or not Path(request.url.path).suffix
):
# 让入口 HTML 每次重新校验,避免新脚本上线后仍被旧页面长期引用。
response.headers["Cache-Control"] = "no-cache"
elif request.method in ("GET", "HEAD") and Path(request.url.path).suffix in (".js", ".css"):
# 前端资源通过 ?v= 更新版本号;保留 ETag 校验以便紧急修复时立即生效。
response.headers["Cache-Control"] = "public, max-age=0, must-revalidate"
if request.url.path.startswith(("/join/", "/duty-confirm/", "/mail-test/")):
kind = "test" if request.url.path.startswith("/mail-test/") else ("duty" if request.url.path.startswith("/duty-confirm/") else "activity")
origin_kind = "none" if not origin else ("null" if origin == "null" else ("trusted" if origin in (own_origin, trusted_origin) else "other"))