Add bundled bus fonts and shared font favorites

This commit is contained in:
2026-10-12 15:00:40 +08:00
parent c9dd03c23b
commit 4be74a34f9
181 changed files with 2078575 additions and 76 deletions
@@ -20,6 +20,7 @@ from PIL import Image
from app.display.colors import parse_color
from app.display.text_renderer import FontResolver, TextOptions, render_text_layer
from app.persistence import atomic_write_bytes, atomic_write_many_bytes
from app.fonts.render_cache import cache_stale, stamp_cache, STAMP_SUFFIX, versioned_url
logger = logging.getLogger(__name__)
@@ -341,7 +342,7 @@ class TemplateStore:
def _write_thumbnail(self, template_id: str, digest: str, scene: dict[str, Any]) -> Path:
path = self._thumbnail_path(template_id, digest)
if path.exists():
if path.exists() and not cache_stale(path, scene, self._font_resolver):
return path
content = render_scene_thumbnail(scene, font_resolver=self._font_resolver)
self._write_bytes_atomic(path, content)
@@ -353,6 +354,7 @@ class TemplateStore:
except Exception:
path.unlink(missing_ok=True)
raise
stamp_cache(path, scene, self._font_resolver)
return path
def _parse_record_document(
@@ -488,7 +490,7 @@ class TemplateStore:
for record in records:
expected.add(record["thumbnail"])
path = self.thumbnails_dir / record["thumbnail"]
if not path.exists():
if not path.exists() or cache_stale(path, record["scene"], self._font_resolver):
try:
self._write_thumbnail(record["id"], record["digest"], record["scene"])
except Exception:
@@ -500,6 +502,8 @@ class TemplateStore:
path.unlink(missing_ok=True)
elif THUMBNAIL_RE.fullmatch(path.name) and path.name not in expected:
path.unlink(missing_ok=True)
elif path.name.endswith(STAMP_SUFFIX) and THUMBNAIL_RE.fullmatch(path.name[:-len(STAMP_SUFFIX)]) and path.name[:-len(STAMP_SUFFIX)] not in expected:
path.unlink(missing_ok=True)
def _ensure_unique_name(self, name: str, exclude_id: str | None = None) -> None:
key = name.casefold()
@@ -518,7 +522,7 @@ class TemplateStore:
"updated_at": record["updated_at"],
"digest": record["digest"],
"revision": record_revision(record),
"thumbnail_url": f"/api/templates/{record['id']}/thumbnail?v={record['digest']}",
"thumbnail_url": versioned_url(f"/api/templates/{record['id']}/thumbnail?v={record['digest']}", record["scene"], self._font_resolver),
"size_bytes": size_bytes,
}