From 958482e5e691fb8447d74540ffd5320e3abc9cf8 Mon Sep 17 00:00:00 2001 From: AskaEth Date: Mon, 27 Jul 2026 11:32:26 +0800 Subject: [PATCH] feat: auto-detect preview image format (jpg/png/webp/gif) --- models/dashboard.py | 9 +++++++++ static/js/pages/dashboard.js | 5 +++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/models/dashboard.py b/models/dashboard.py index 1e1f276..cc71147 100644 --- a/models/dashboard.py +++ b/models/dashboard.py @@ -35,6 +35,7 @@ class DashboardTheme: updated_at: str = "" is_builtin: bool = False dir_path: str = "" + preview_ext: str = "" def to_dict(self) -> dict[str, Any]: return { @@ -51,6 +52,7 @@ class DashboardTheme: "created_at": self.created_at, "updated_at": self.updated_at, "is_builtin": self.is_builtin, + "preview_ext": self.preview_ext, } @classmethod @@ -59,6 +61,12 @@ class DashboardTheme: with open(manifest_path, "r", encoding="utf-8") as f: data = json.load(f) config = data.get("config", {}) + dir_path = manifest_path.parent + preview_ext = "" + for ext in ["jpg", "jpeg", "png", "webp", "gif"]: + if (dir_path / f"preview.{ext}").exists(): + preview_ext = ext + break return cls( id=data.get("id", manifest_path.parent.name), name=data.get("name", manifest_path.parent.name), @@ -74,6 +82,7 @@ class DashboardTheme: updated_at=data.get("updated_at", ""), is_builtin=is_builtin, dir_path=str(manifest_path.parent), + preview_ext=preview_ext, ) except Exception as e: logger.error("Failed to load dashboard manifest %s: %s", manifest_path, e) diff --git a/static/js/pages/dashboard.js b/static/js/pages/dashboard.js index 7e13f31..69e74ef 100644 --- a/static/js/pages/dashboard.js +++ b/static/js/pages/dashboard.js @@ -289,10 +289,11 @@ const PageDashboard = { const isAll = supported === 'all'; const compatLabel = isAll ? '全' : '限'; const compatClass = isAll ? 'badge-info' : 'badge-warning'; - const preview = `/dashboard/${theme.id}/preview.jpg`; + const preview = theme.preview_ext ? `/dashboard/${theme.id}/preview.${theme.preview_ext}` : ''; + const bgStyle = preview ? `background-image:url(${preview});background-size:cover;background-position:center` : ''; return `
-
${icon}
+
${preview?'':icon}
${theme.name || 'Unnamed'}