fix
This commit is contained in:
@@ -43,7 +43,6 @@ let
|
||||
import cairosvg
|
||||
from PIL import Image
|
||||
|
||||
|
||||
CONFIG_PATH = os.environ.get("FAVICON_CONFIG", "/config/config.json")
|
||||
LOGO_PATH = os.environ.get("FAVICON_LOGO", "/assets/logo.svg")
|
||||
CACHE_DIR = Path(os.environ.get("FAVICON_CACHE_DIR", "/cache"))
|
||||
@@ -51,27 +50,22 @@ let
|
||||
LISTEN_PORT = int(os.environ.get("FAVICON_PORT", "8080"))
|
||||
DEFAULT_CACHE_CONTROL = "public, max-age=86400"
|
||||
|
||||
|
||||
with open(CONFIG_PATH, "r", encoding="utf-8") as fh:
|
||||
APP_CONFIG = json.load(fh)
|
||||
with open(LOGO_PATH, "rb") as fh:
|
||||
LOGO_BYTES = fh.read()
|
||||
LOGO_HASH = hashlib.sha256(LOGO_BYTES).hexdigest()
|
||||
|
||||
|
||||
def _normalize_host(host):
|
||||
return (host or "").split(":", 1)[0].strip().lower()
|
||||
|
||||
|
||||
def _pick_profile(host):
|
||||
mappings = APP_CONFIG.get("mappings", {})
|
||||
return mappings.get(host) or APP_CONFIG.get("default")
|
||||
|
||||
|
||||
def _color(value, fallback):
|
||||
return value if isinstance(value, str) and value else fallback
|
||||
|
||||
|
||||
def _tinted_logo_data_uri(color):
|
||||
svg = LOGO_BYTES.decode("utf-8")
|
||||
svg = re.sub(
|
||||
@@ -112,7 +106,6 @@ let
|
||||
)
|
||||
return "data:image/svg+xml;base64," + base64.b64encode(svg.encode("utf-8")).decode("ascii")
|
||||
|
||||
|
||||
def _border_radius():
|
||||
value = APP_CONFIG.get("borderRadius", "8")
|
||||
text = str(value).strip()
|
||||
@@ -120,7 +113,6 @@ let
|
||||
return text
|
||||
return f"{text}px"
|
||||
|
||||
|
||||
def _render_svg(profile):
|
||||
bg = _color(profile.get("background"), "#111827")
|
||||
fg = _color(profile.get("foreground"), "#f8fafc")
|
||||
@@ -133,17 +125,8 @@ let
|
||||
<image href="{logo_data_uri}" x="0" y="0" width="{canvas}" height="{canvas}" preserveAspectRatio="xMidYMid meet" />
|
||||
</svg>"""
|
||||
|
||||
|
||||
def _cache_key(host, profile):
|
||||
payload = json.dumps(
|
||||
{"host": host, "profile": profile, "logo": LOGO_HASH},
|
||||
sort_keys=True,
|
||||
).encode("utf-8")
|
||||
return hashlib.sha256(payload).hexdigest()
|
||||
|
||||
|
||||
def _generate_asset(host, profile):
|
||||
cache_name = f"{_cache_key(host, profile)}.ico"
|
||||
cache_name = f"{host}.ico"
|
||||
target = CACHE_DIR / cache_name
|
||||
if target.exists():
|
||||
return target
|
||||
@@ -156,7 +139,6 @@ let
|
||||
image.close()
|
||||
return target
|
||||
|
||||
|
||||
class Handler(BaseHTTPRequestHandler):
|
||||
server_version = "favicon-router/1.0"
|
||||
|
||||
@@ -186,7 +168,6 @@ let
|
||||
def log_message(self, fmt, *args):
|
||||
print("%s - - [%s] %s" % (self.address_string(), self.log_date_time_string(), fmt % args))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
httpd = ThreadingHTTPServer((LISTEN_HOST, LISTEN_PORT), Handler)
|
||||
httpd.serve_forever()
|
||||
|
||||
Reference in New Issue
Block a user