26 Commits

Author SHA1 Message Date
Chuck
448a15c1e6 feat(fonts): add dynamic font selection and font manager improvements (#232)
* feat(fonts): add dynamic font selection and font manager improvements

- Add font-selector widget for dynamic font selection in plugin configs
- Enhance /api/v3/fonts/catalog with filename, display_name, and type
- Add /api/v3/fonts/preview endpoint for server-side font rendering
- Add /api/v3/fonts/<family> DELETE endpoint with system font protection
- Fix /api/v3/fonts/upload to actually save uploaded font files
- Update font manager tab with dynamic dropdowns, server-side preview, and font deletion
- Add new BDF fonts: 6x10, 6x12, 6x13, 7x13, 7x14, 8x13, 9x15, 9x18, 10x20 (with bold/oblique variants)
- Add tom-thumb, helvR12, clR6x12, texgyre-27 fonts

Plugin authors can use x-widget: "font-selector" in schemas to enable
dynamic font selection that automatically shows all available fonts.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* fix(fonts): security fixes and code quality improvements

- Fix README.md typos and add language tags to code fences
- Remove duplicate delete_font function causing Flask endpoint collision
- Add safe integer parsing for size parameter in preview endpoint
- Fix path traversal vulnerability in /fonts/preview endpoint
- Fix path traversal vulnerability in /fonts/<family> DELETE endpoint
- Fix XSS vulnerability in fonts.html by using DOM APIs instead of innerHTML
- Move baseUrl to shared scope to fix ReferenceError in multiple functions

Security improvements:
- Validate font filenames reject path separators and '..'
- Validate paths are within fonts_dir before file operations
- Use textContent and data attributes instead of inline onclick handlers
- Restrict file extensions to known font types

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* fix(fonts): address code issues and XSS vulnerabilities

- Move `import re` to module level, remove inline imports
- Remove duplicate font_file assignment in upload_font()
- Remove redundant validation with inconsistent allowed extensions
- Remove redundant PathLib import, use already-imported Path
- Fix XSS vulnerabilities in fonts.html by using DOM APIs instead of
  innerHTML with template literals for user-controlled data

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* fix(fonts): add size limits to font preview endpoint

Add input validation to prevent DoS via large image generation:
- MAX_TEXT_CHARS (100): Limit text input length
- MAX_TEXT_LINES (3): Limit number of newlines
- MAX_DIM (1024): Limit max width/height
- MAX_PIXELS (500000): Limit total pixel count

Validates text early before processing and checks computed
dimensions after bbox calculation but before image allocation.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* fix(fonts): improve error handling, catalog keys, and BDF preview

- Add structured logging for cache invalidation failures instead of
  silent pass (FontUpload, FontDelete, FontCatalog contexts)
- Use filename as unique catalog key to prevent collisions when
  multiple font files share the same family_name from metadata
- Return explicit error for BDF font preview instead of showing
  misleading preview with default font

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* fix(fonts): address nitpick issues in font management

Frontend (fonts.html):
- Remove unused escapeHtml function (dead code)
- Add max-attempts guard (50 retries) to initialization loop
- Add response.ok checks before JSON parsing in deleteFont,
  addFontOverride, deleteFontOverride, uploadSelectedFonts
- Use is_system flag from API instead of hardcoded client-side list

Backend (api_v3.py):
- Move SYSTEM_FONTS to module-level frozenset for single source of truth
- Add is_system flag to font catalog entries
- Simplify delete_font system font check using frozenset lookup

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* fix(fonts): align frontend upload validation with backend

- Add .otf to accepted file extensions (HTML accept attribute, JS filter)
- Update validation regex to allow hyphens (matching backend)
- Preserve hyphens in auto-generated font family names
- Update UI text to reflect all supported formats

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* fix(fonts): fix lint errors and missing variable

- Remove unused exception binding in set_cached except block
- Define font_family_lower before case-insensitive fallback loop
- Add response.ok check to font preview fetch (consistent with other handlers)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* fix(fonts): address nitpick code quality issues

- Add return type hints to get_font_preview and delete_font endpoints
- Catch specific PIL exceptions (IOError/OSError) when loading fonts
- Replace innerHTML with DOM APIs for trash icon (consistency)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* fix(fonts): remove unused exception bindings in cache-clearing blocks

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Chuck <chuck@example.com>
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-11 18:21:27 -05:00
Chuck
d10aed8fe5 trying x version 2025-07-23 12:59:48 -05:00
Chuck
78f014cad3 new fonts: Matrix light & chunky 2025-07-23 12:58:49 -05:00
Chuck
53464e0971 font change to MatrixLight8X 2025-07-23 12:55:26 -05:00
Chuck
e7100c4cba font change to cozette 2025-07-23 12:53:26 -05:00
Chuck
5518810889 new font 2025-07-23 12:48:15 -05:00
Chuck
e54a25da78 new font 2025-07-23 12:46:55 -05:00
Chuck
aa0472e5c5 new font try 2 2025-07-23 12:07:02 -05:00
Chuck
f3f50b87af try font change setting 2025-07-23 12:04:19 -05:00
Chuck
c6b7d2a5cc switching to TTF font 2025-07-23 11:24:10 -05:00
Chuck
553a857cb6 try new font, Cozette 2025-07-23 09:50:16 -05:00
Chuck
4e56f88463 try new font 2025-07-23 08:37:15 -05:00
Chuck
eb96285a5c left justify OTD display and update font display to test 5x7regular 2025-07-22 21:38:43 -05:00
ChuckBuilds
f32791d23d remove tomthumb font 2025-04-25 10:31:47 -05:00
ChuckBuilds
beceae1f78 added 5x7.bdf 2025-04-23 17:48:39 -05:00
ChuckBuilds
1ab87d29b8 feat: switch calendar font from tom-thumb.bdf to 4x6.bdf 2025-04-23 15:09:52 -05:00
ChuckBuilds
5cfda2be9c rename bdf_font_guide 2025-04-23 14:55:24 -05:00
ChuckBuilds
c9c92ac0fb notes on how to use bdf fonts added to fonts folder 2025-04-22 20:37:02 -05:00
Chuck
9ddff0ba78 Create tom-thumb.bdf
added font
2025-04-22 19:43:21 -05:00
Chuck
6bdc26e170 Delete m3x6.ttf
remove m3x6
2025-04-22 19:41:19 -05:00
Chuck
bece39aece Create m3x6.ttf
add font
2025-04-22 19:36:51 -05:00
Chuck
fea6aa1542 Create MatrixChunky6.ttf
added 6 pixel font
2025-04-22 17:42:33 -05:00
ChuckBuilds
3d83930e0b spacing adjustment on weather and clock. Added notes to readme about font type requing ttf. removed sensitive credentials 2025-04-15 15:55:47 -05:00
ChuckBuilds
05d2a3f97e added 4x6-font.ttf 2025-04-15 15:43:23 -05:00
ChuckBuilds
4683a175c5 change font on bottom half weather display 2025-04-15 11:02:36 -05:00
Chuck
27da4a573b font change
font changed to Press Start 2P
2025-04-08 19:10:57 -05:00