fix(ui): кэш-бастинг главной страницы (chat.html) — как у /admin

Причина «в интерфейсе ничего не поменялось»: GET / отдавал chat.html БЕЗ анти-кэш
заголовков → браузер держал старую копию. Теперь / без актуального ?v= → 302 на
/?v=APP_VERSION (сохраняя ?tab=) → промах кэша → no-store. Новые версии подхватываются
сами, без Ctrl+Shift+R. APP_VERSION 2026-07-17t.
This commit is contained in:
anor
2026-07-18 00:21:06 +10:00
parent 4000ac84cb
commit 3f35cdc441
+19 -3
View File
@@ -138,7 +138,7 @@ MAX_MESSAGE_LEN = 10_000
# ⚠️ Версия UI — единый источник. БАМПАТЬ ПРИ КАЖДОМ ДЕПЛОЕ (формат: YYYY-MM-DD + буква).
# Фронт берёт её через GET /api/version (chat.html + admin.html, элемент .app-version).
APP_VERSION = "2026-07-17s"
APP_VERSION = "2026-07-17t"
# Audit: path → action name mapping
_AUDIT_MAP = [
@@ -265,8 +265,24 @@ def _get_tab(request: Request, body: dict | None = None) -> str:
@app.get("/", response_class=HTMLResponse)
async def index():
return Path("static/chat.html").read_text(encoding="utf-8")
async def index(request: Request):
# Кэш-бастинг главной (как /admin): без актуального ?v= → 302 на URL с v=APP_VERSION
# (новый URL ≠ закэшированный без query → промах кэша → свежий запрос → no-store).
# Прочие параметры (?tab=) сохраняем. Иначе браузер держит старый chat.html навсегда.
from fastapi.responses import RedirectResponse
from urllib.parse import urlencode
if request.query_params.get("v") != APP_VERSION:
params = dict(request.query_params)
params["v"] = APP_VERSION
return RedirectResponse(url=f"/?{urlencode(params)}", status_code=302)
return HTMLResponse(
Path("static/chat.html").read_text(encoding="utf-8"),
headers={
"Cache-Control": "no-store, no-cache, must-revalidate, max-age=0",
"Pragma": "no-cache",
"Expires": "0",
},
)
@app.get("/api/version")