update model

This commit is contained in:
vee
2026-08-14 11:17:17 +08:00
parent 1a96d39426
commit 6d768aaef4
56 changed files with 424 additions and 148 deletions
+16 -5
View File
@@ -243,7 +243,7 @@ class SeatDemoHandler(BaseHTTPRequestHandler):
if path.startswith("/api/requests/"):
self._serve_request(path.removeprefix("/api/requests/"))
return
self._serve_static(path)
self._serve_static(path, parsed_url.query)
def do_POST(self) -> None: # noqa: N802 - stdlib handler API
path = unquote(urlparse(self.path).path)
@@ -942,17 +942,24 @@ class SeatDemoHandler(BaseHTTPRequestHandler):
return
self._json(json.loads(result_path.read_text(encoding="utf-8")))
def _serve_static(self, path: str) -> None:
def _serve_static(self, path: str, query: str = "") -> None:
relative_path = "index.html" if path in {"", "/"} else path.lstrip("/")
self._serve_static_file(relative_path)
versioned = bool(parse_qs(query).get("v"))
self._serve_static_file(relative_path, versioned=versioned)
def _serve_static_file(self, relative_path: str) -> None:
def _serve_static_file(self, relative_path: str, *, versioned: bool = False) -> None:
candidate = (STATIC_ROOT / relative_path).resolve()
try:
candidate.relative_to(STATIC_ROOT.resolve())
except ValueError:
self._json({"error": "not_found"}, HTTPStatus.NOT_FOUND)
return
if not candidate.is_file() and (
Path(relative_path).suffix
or relative_path.startswith(("assets/", "vendor/", "icons/"))
):
self._json({"error": "not_found"}, HTTPStatus.NOT_FOUND)
return
if not candidate.is_file():
candidate = STATIC_ROOT / "index.html"
content_type, _ = mimetypes.guess_type(candidate.name)
@@ -972,8 +979,12 @@ class SeatDemoHandler(BaseHTTPRequestHandler):
)
self.send_header("Content-Length", str(len(content)))
cache_control = "no-cache"
if relative_path.startswith(("vendor/", "assets/", "icons/")):
if relative_path.startswith(("vendor/", "icons/")) or (
relative_path.startswith("assets/") and versioned
):
cache_control = "public, max-age=31536000, immutable"
elif relative_path.startswith("assets/"):
cache_control = "no-cache"
elif candidate.name in {"index.html", "login.html", "service-worker.js"}:
cache_control = "no-cache"
self.send_header("Cache-Control", cache_control)