From 4218bb8344dc84456ac066df4cf317e104f508ea Mon Sep 17 00:00:00 2001 From: soraefir Date: Sun, 7 Jun 2026 14:43:00 +0200 Subject: [PATCH] fix --- modules/server/containers/apps/favicon.nix | 29 +++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/modules/server/containers/apps/favicon.nix b/modules/server/containers/apps/favicon.nix index e57ff03..823d63a 100644 --- a/modules/server/containers/apps/favicon.nix +++ b/modules/server/containers/apps/favicon.nix @@ -140,8 +140,26 @@ let """ + def _cache_key(host, profile): + bg = _color(profile.get("bg") or profile.get("background"), "#111827") + fg = _color(profile.get("fg") or profile.get("foreground"), "#f8fafc") + cache_inputs = { + "asset_size": ASSET_SIZE, + "bg": bg, + "border_radius": _border_radius(), + "fg": fg, + "host": host, + "logo_hash": LOGO_HASH, + } + payload = json.dumps(cache_inputs, sort_keys=True, separators=(",", ":")) + return hashlib.sha256(payload.encode("utf-8")).hexdigest()[:16] + + def _cache_name(host, profile): + safe_host = re.sub(r"[^a-z0-9.-]+", "_", host or "default") + return f"{safe_host}-{_cache_key(host, profile)}.ico" + def _generate_asset(host, profile): - cache_name = f"{host}.ico" + cache_name = _cache_name(host, profile) target = CACHE_DIR / cache_name if target.exists(): return target @@ -165,11 +183,20 @@ let return asset_path = _generate_asset(host, profile) + etag = f'"{asset_path.stem.rsplit("-", 1)[-1]}"' + if self.headers.get("If-None-Match") == etag: + self.send_response(304) + self.send_header("ETag", etag) + self.send_header("Cache-Control", APP_CONFIG.get("cacheControl", DEFAULT_CACHE_CONTROL)) + self.end_headers() + return + payload = asset_path.read_bytes() self.send_response(200) self.send_header("Content-Type", "image/x-icon") self.send_header("Content-Length", str(len(payload))) self.send_header("Cache-Control", APP_CONFIG.get("cacheControl", DEFAULT_CACHE_CONTROL)) + self.send_header("ETag", etag) self.end_headers() if include_body: self.wfile.write(payload)