fix
This commit is contained in:
@@ -140,8 +140,26 @@ let
|
|||||||
<image href="{logo_data_uri}" x="0" y="0" width="{canvas}" height="{canvas}" preserveAspectRatio="xMidYMid meet" />
|
<image href="{logo_data_uri}" x="0" y="0" width="{canvas}" height="{canvas}" preserveAspectRatio="xMidYMid meet" />
|
||||||
</svg>"""
|
</svg>"""
|
||||||
|
|
||||||
|
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):
|
def _generate_asset(host, profile):
|
||||||
cache_name = f"{host}.ico"
|
cache_name = _cache_name(host, profile)
|
||||||
target = CACHE_DIR / cache_name
|
target = CACHE_DIR / cache_name
|
||||||
if target.exists():
|
if target.exists():
|
||||||
return target
|
return target
|
||||||
@@ -165,11 +183,20 @@ let
|
|||||||
return
|
return
|
||||||
|
|
||||||
asset_path = _generate_asset(host, profile)
|
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()
|
payload = asset_path.read_bytes()
|
||||||
self.send_response(200)
|
self.send_response(200)
|
||||||
self.send_header("Content-Type", "image/x-icon")
|
self.send_header("Content-Type", "image/x-icon")
|
||||||
self.send_header("Content-Length", str(len(payload)))
|
self.send_header("Content-Length", str(len(payload)))
|
||||||
self.send_header("Cache-Control", APP_CONFIG.get("cacheControl", DEFAULT_CACHE_CONTROL))
|
self.send_header("Cache-Control", APP_CONFIG.get("cacheControl", DEFAULT_CACHE_CONTROL))
|
||||||
|
self.send_header("ETag", etag)
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
if include_body:
|
if include_body:
|
||||||
self.wfile.write(payload)
|
self.wfile.write(payload)
|
||||||
|
|||||||
Reference in New Issue
Block a user