From d3ae2459ce0496dd485b0df00adb36a5ab4352d3 Mon Sep 17 00:00:00 2001 From: Mikhail Date: Sun, 17 May 2026 11:48:43 +0300 Subject: [PATCH] Version HTML5 asset URLs --- services/api-server/src/api_server/html5.py | 18 +++++++++++++++--- services/api-server/src/api_server/main.py | 2 +- services/api-server/tests/test_api.py | 18 +++++++++--------- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/services/api-server/src/api_server/html5.py b/services/api-server/src/api_server/html5.py index b8f37c2..41388a4 100644 --- a/services/api-server/src/api_server/html5.py +++ b/services/api-server/src/api_server/html5.py @@ -1,8 +1,11 @@ from __future__ import annotations from html import escape +from pathlib import Path from urllib.parse import quote +_HTML5_ASSETS_DIR = Path(__file__).resolve().parent / "static" / "html5" + def _page(title: str, body: str) -> str: return f""" @@ -11,14 +14,23 @@ def _page(title: str, body: str) -> str: {escape(title)} - - - + + + {body} """ +def _asset_url(filename: str) -> str: + asset_path = _HTML5_ASSETS_DIR / filename + try: + version = str(int(asset_path.stat().st_mtime)) + except OSError: + version = "dev" + return f"/html5/assets/{quote(filename)}?v={version}" + + def _project_link(project: object, active_project_id: str) -> str: project_id = str(getattr(project, "project_id", "")) name = str(getattr(project, "name", project_id)) diff --git a/services/api-server/src/api_server/main.py b/services/api-server/src/api_server/main.py index 140f141..5cc50d1 100644 --- a/services/api-server/src/api_server/main.py +++ b/services/api-server/src/api_server/main.py @@ -140,7 +140,7 @@ _HTML5_ASSETS_DIR = Path(__file__).resolve().parent / "static" / "html5" class Html5StaticFiles(StaticFiles): def file_response(self, *args, **kwargs): response = super().file_response(*args, **kwargs) - response.headers.setdefault("Cache-Control", "public, max-age=3600") + response.headers.setdefault("Cache-Control", "public, max-age=86400") return response diff --git a/services/api-server/tests/test_api.py b/services/api-server/tests/test_api.py index 74936af..7556cb4 100644 --- a/services/api-server/tests/test_api.py +++ b/services/api-server/tests/test_api.py @@ -35,9 +35,9 @@ def assert_html5_contract(text: str, *markers: str, full_page: bool = False) -> if full_page: assert "" in text assert "