feat(backend): signage playlists and slides, screens, built-in pictures (platform-v2 step 5.4a)
- signage_playlists (name, orientation, default transition) and signage_slides (kind menu | image | video | text, position, duration, transition, video to its end, on/off, days / hours / dates, content typed per kind: extra fields refused, pictures / videos as media ids). Alembic 0029. - /api/signage: playlists CRUD, duplicate, timeline order; slides add (at a position), change, delete, duplicate; screens (playlist, orientation, rotation, orientation mismatch). The screen's GET /api/signage/screen gives its playlist resolved for playing with a version hash. Changes send signage.changed only to the screens playing that playlist. - Signage device config: playlist (ref signage_playlists), orientation, rotation. Slides register their media usage. - Built-in pictures: assets/builtin_media/ imported at start (media.builtin), a collection of their own (?collection=builtin|own), never deleted or renamed (media.builtin). - tests: test_signage.py (8); 509 passed. Pack README: the signage row. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -334,3 +334,46 @@ def uses(db, media_id: int) -> list[dict]:
|
||||
for u in fn(db, media_id) or ():
|
||||
found.append({"kind": kind, **u})
|
||||
return found
|
||||
|
||||
|
||||
# ── built-in pictures (shipped with the server, step 5.4a) ──────────────────
|
||||
|
||||
BUILTIN_DIR = os.environ.get("XENIA_BUILTIN_MEDIA_DIR",
|
||||
os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "assets", "builtin_media"))
|
||||
_PICTURE_EXT = (".jpg", ".jpeg", ".png", ".webp", ".avif", ".gif")
|
||||
|
||||
|
||||
def import_builtin(db, folder: str | None = None) -> int:
|
||||
"""Bring the built-in pictures into the library (start-up). Already there (same bytes) → marked
|
||||
built-in. Returns how many were added. A file that can't be read is logged and skipped."""
|
||||
import logging
|
||||
from models.media import Media
|
||||
log = logging.getLogger("xenia.media")
|
||||
folder = folder or BUILTIN_DIR
|
||||
try:
|
||||
names = sorted(n for n in os.listdir(folder) if n.lower().endswith(_PICTURE_EXT))
|
||||
except FileNotFoundError:
|
||||
return 0
|
||||
added = 0
|
||||
for n in names:
|
||||
path = os.path.join(folder, n)
|
||||
try:
|
||||
sha, size, info = ingest_path(path)
|
||||
except Exception as e: # refused or unreadable
|
||||
log.warning("built-in picture %s skipped (%s)", n, getattr(e, "code", e))
|
||||
continue
|
||||
row = db.query(Media).filter(Media.sha256 == sha).first()
|
||||
if row is not None:
|
||||
if not row.builtin:
|
||||
row.builtin = True
|
||||
continue
|
||||
if not info: # files there but no row (an earlier failed start)
|
||||
delete_files(sha)
|
||||
sha, size, info = ingest_path(path)
|
||||
stem = os.path.splitext(n)[0].replace("_", " ").replace("-", " ").strip()
|
||||
db.add(Media(name=(stem or "picture")[:120], original_name=n, sha256=sha, bytes=size, builtin=True, **info))
|
||||
added += 1
|
||||
db.commit()
|
||||
if added:
|
||||
log.info("built-in pictures added to the library: %d", added)
|
||||
return added
|
||||
|
||||
Reference in New Issue
Block a user