chore: phase 5 wrap-up (platform-v2 5.99)

- THIRD_PARTY_NOTICES.md in the backend image: FFmpeg (GPL v3, via imageio-ffmpeg)
- video.requeue_missing(): videos whose still frame is gone (a partial restore) are prepared
  again when the backend starts (+1 test, backend 542 passed)
- pack README: data/media belongs in every site backup with pos.db
- stack.mjs: the test video is unique per run (the stack keeps its data between runs)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-18 03:06:48 +02:00
co-authored by Claude Opus 5.5
parent b5361e10ca
commit 218a6c9c5e
5 changed files with 59 additions and 2 deletions
+1 -1
View File
@@ -47,7 +47,7 @@ The manager calls the API **same-origin, with relative paths**. The waiter app r
| `local_backend/services/table_qr.py`, `services/qr_orders.py` | The QR menu at the table (phase 3S): every active table has a random `qr_token`; the menu snapshot carries only its sha256 (`qr`), so the cloud can check a code but never make one. A new code (rotate) kills the printed one at the next push (`/api/tables` and `/api/connect/qr` are in `MENU_PATHS`). A QR order with a valid table goes straight onto the table's open order (or a new one), to the kitchen, with a `qr_order` message to the table's waiters; the audit row `QR_ORDER` (note = the cloud ref) keeps repeats out. Manager page `/online/qr` |
| `local_backend/routers/fees.py` | The venue's online ordering settings (`connect_orders.ordering`: services, hours, slots, ASAP; `reservations`: bookings, food ahead, fire minutes), delivery areas and fee rules, the fee line's name/VAT, and the venue's links (`links.order`, `links.menu` from the cloud's `apps_url`). Everything here travels to the cloud in the menu snapshot (contract C-2) |
| `local_backend/routers/customer_display.py`, `models/display_look.py`, `terminal/src/apps/customer-display/` | The customer display (3.4, 5.3): the counter POS pushes `POST /api/display/state` (`useDisplay()` in `apps/pos/usePos.js`: the sale cart, the payment dialog's bill, then "paid"); only displays whose `linked_device_id` is that POS get `display.state`. The idle screen is a **look** (`display_looks`: name, `is_default`, config = style, message, theme, QR, pictures as media library ids; looks register their media usage). One look is the venue's default; a display shows the look in its device config `look` (a `ref` to `display_looks`, also set from Settings → Customer display through `PUT /api/display/displays/{id}/look`) or the default. A look's change sends `display.settings` only to the displays showing it. Pictures are served from the library (`full` for image / slides, `card` for the logo). The POS's last state lives in memory |
| `local_backend/routers/media.py`, `services/media.py`, `models/media.py`; manager `src/pages/media/` | The media library (5.1, 5.2): every picture and video once, by sha256, under `/app/data/media/<sha[:2]>/<sha>/` (the untouched original + `thumb` 200 / `card` 600 / `full` 1920 WebP for pictures, AVIF accepted; videos kept as uploaded). Served public by hash at `/api/media/file/<sha>/<variant>` with year-long `immutable` caching (a different file is a different URL; byte ranges for video). The display name is only for people; files on disk are named by the backend. Whoever manages the menu, customer display, signage or menu tablets manages it. **What points at media has a `media_id` column and registers `register_usage(kind, fn)`** (products and categories in `routers/products.py`) so delete is refused (`media.in_use`) while it's used. APIs give `image` = `{id, name, thumb, card, full}` (`services.media.image_of`); a product's `image_url` is its card size. Manager: the Media page (batch upload, details) and `MediaField` (upload on the spot / pick from the library / "Name it after" with `latin()` from `@xenia/i18n`) for any form that takes a picture. The waiter fetches the menu's photos ahead (`services/photoCache.js`; PWA: workbox `xenia-media` cache-first) so they show offline. Upload limits: 20 MB pictures, 200 MB videos; every nginx config sets `client_max_body_size 250m`. **Videos (5.4e, `services/video.py`):** MP4 / MOV / WebM kept as uploaded; a background thread (`start_worker` in `main.py`'s lifespan, one video at a time, low priority, 2 threads) makes the still frame (the same `thumb` / `card` / `full` WebP) and, when `needs_version()` says so (not H.264 MP4, over 1920 px, 10-bit / HDR, other audio, > 12 Mbps), `play.mp4` (H.264 + AAC, ≤ 1920 px, HDR tone-mapped, faststart). `Media.processing` waiting → working (`progress`) → done | failed; migration 0031 queues existing videos. ffmpeg comes from the pinned `imageio-ffmpeg` wheel (static, Linux x86-64 / ARM64 / Windows; `XENIA_FFMPEG` overrides); without it videos stay as uploaded (`processing` null). `urls` gains `thumb`/`card`/`full`/`play` as they exist; `media.video_src()` is what a screen plays; `video.on_done(fn)` listeners (signage tells the screens playing it) |
| `local_backend/routers/media.py`, `services/media.py`, `models/media.py`; manager `src/pages/media/` | The media library (5.1, 5.2): every picture and video once, by sha256, under `/app/data/media/<sha[:2]>/<sha>/` (the untouched original + `thumb` 200 / `card` 600 / `full` 1920 WebP for pictures, AVIF accepted; videos kept as uploaded). **`data/media` belongs in every site backup together with `pos.db`** (the database only holds ids and hashes; DEPLOYMENT_GUIDE → Backups). Served public by hash at `/api/media/file/<sha>/<variant>` with year-long `immutable` caching (a different file is a different URL; byte ranges for video). The display name is only for people; files on disk are named by the backend. Whoever manages the menu, customer display, signage or menu tablets manages it. **What points at media has a `media_id` column and registers `register_usage(kind, fn)`** (products and categories in `routers/products.py`) so delete is refused (`media.in_use`) while it's used. APIs give `image` = `{id, name, thumb, card, full}` (`services.media.image_of`); a product's `image_url` is its card size. Manager: the Media page (batch upload, details) and `MediaField` (upload on the spot / pick from the library / "Name it after" with `latin()` from `@xenia/i18n`) for any form that takes a picture. The waiter fetches the menu's photos ahead (`services/photoCache.js`; PWA: workbox `xenia-media` cache-first) so they show offline. Upload limits: 20 MB pictures, 200 MB videos; every nginx config sets `client_max_body_size 250m`. **Videos (5.4e, `services/video.py`):** MP4 / MOV / WebM kept as uploaded; a background thread (`start_worker` in `main.py`'s lifespan, one video at a time, low priority, 2 threads) makes the still frame (the same `thumb` / `card` / `full` WebP) and, when `needs_version()` says so (not H.264 MP4, over 1920 px, 10-bit / HDR, other audio, > 12 Mbps), `play.mp4` (H.264 + AAC, ≤ 1920 px, HDR tone-mapped, faststart). `Media.processing` waiting → working (`progress`) → done | failed; migration 0031 queues existing videos. ffmpeg comes from the pinned `imageio-ffmpeg` wheel (static, Linux x86-64 / ARM64 / Windows; `XENIA_FFMPEG` overrides); without it videos stay as uploaded (`processing` null). `urls` gains `thumb`/`card`/`full`/`play` as they exist; `media.video_src()` is what a screen plays; `video.on_done(fn)` listeners (signage tells the screens playing it) |
| `local_backend/routers/signage.py`, `models/signage.py`, `assets/builtin_media/` | Digital signage (5.4a): **playlists** (name, orientation, default transition) of **slides** (kind menu / image / video / text, position, duration, transition, video to its end, on / off, days / hours / dates window, `content` typed per kind in the router: extra fields refused, pictures and videos as media ids, walked by `media_ids()` for the library's usage check). A screen's device config: `playlist` (ref `signage_playlists`), `orientation`, `rotation`; `GET /api/signage/screen` gives it the playlist resolved (enabled slides, media addresses, a `version` hash); changes send `signage.changed` only to the screens playing that playlist. **Built-in pictures:** files in `assets/builtin_media/` are imported at start (`services.media.import_builtin`, `media.builtin`), listed as their own collection, never deleted or renamed. **Menu boards (5.4b):** `services/signage_menu.py` resolves a menu slide (all / whole categories incl. sub-categories, live / single products, minus exclusions; the board's own `category_order` / `product_order`; prices from `pos_cart.unit_prices` of its sales point; customer-facing names); every request that changes the menu (`cloud_sync.menu_changed` paths) also sends `signage.changed` to the screens with a menu board (`main._signage_menu_changed`). **The editor (5.6a):** manager `src/pages/signage/` (Management → Signage): playlists, the timeline (drag / arrows, duplicate, remove), a slide's settings with a live preview (`SlidePreview`), templates (`signageLogic.TEMPLATES`), the orientation warning; `GET /api/signage/venue` and `POST /api/signage/preview/menu` feed the previews. The menu board editor (5.6b, `MenuEditor.jsx`) orders what the server resolved: `boardOrder()` writes the whole shown order into `category_order` / `product_order`; widgets: `WidgetsEditor.jsx`. Tabs (5.6c): Screens (`ScreensTab`: playlist, schedule, shape, rotation through `PUT /api/signage/screens/{id}`), Schedules (`SchedulesTab`), Message and weather (`SignageSettingsTab`: `PUT /api/signage/message`, the town search and `PUT /api/signage/weather/place`). **Widgets (5.4c):** `Widget` on text and menu slides (logo, name, date, clock, message, QR, weather; position, size); the screen also gets `venue` = name, the message of the day (`signage.message`, `PUT /api/signage/message` tells every screen) and the weather (`services/weather.py`: Open-Meteo, no key, every 30 min by the signage worker, kept in memory; `null` when there is no place, no internet or it is older than 3 h, so the player hides the widget). **Schedules (5.4d):** `signage_schedules` (entries {playlist, days, hours that may pass midnight, dates, priority} + a fallback); a screen's `schedule` (ref) wins over its `playlist`; `services/signage_schedule.pick` chooses in venue time (highest priority, then dates > days > hours, then the later entry); `/screen` then carries the schedule (with the venue's time zone) and every playlist in it so the player switches offline; `schedule_worker` (30 s) tells a screen when its pick changes. **The player (5.5a):** `terminal/src/apps/signage/` (the logic and slides moved to `packages/signage` in 5.6a; the schedule pick ported from Python with the same test cases, slide windows, next slide, frame rotation; `SignageApp.jsx`: the last `/screen` answer in localStorage, every picture / video (≤ 120 MB) as an in-memory blob copy, so it plays with the server down; reads again on `signage.changed`, `device.updated`, a reconnect and every 5 min). Signage is in `QUIET_OFFLINE` (`apps/registry.js`): no offline banner, a small mark. The terminal is plain HTTP (no service worker), so a TV that restarts while the server is down waits for it. Menu boards page by themselves (`boardPages`: rows that fit from the frame's shape, text size, photos / descriptions, title and widget bars; `page_size` overrides) and go round while the slide lasts (at least its pages × `page_seconds`); widgets in `Slides.jsx` (`Widgets`), a widget with nothing to show (no weather, no message) is left out |
| `local_backend/routers/menu_tablet.py`, `terminal/src/apps/menu-tablet/` | The menu tablet (5.7a): `GET /api/menu-tablet/menu` (a paired tablet) gives categories in the catalogue's order with their products (a product in several categories shows in each), the products once with the tablet's sales point price, photos, tags, and its device config (view compact / expanded / full, photos, descriptions, group, theme, prices of, sold out, one category, search, languages, idle reset). Menu changes send `menu_tablet.changed` (the same hook as signage). The app: search folds accents and also matches names typed in Latin letters (`latin`, `@xenia/i18n/latin`); the last menu in localStorage. **Call a waiter (5.7b):** device config `table` (ref `tables`) + `call_waiter`; `POST /api/menu-tablet/call` sends a `table_call` staff message (the open order's waiters, else the zone's; `qr_orders.waiters_for`) at most once a minute per tablet (in memory); the waiter's phone shows it with "Open the table" |
| `local_backend/routers/phone.py`, `services/caller_id.py` | Caller ID (3.5): the UCM's `GET /api/phone/call-event` is public but **LAN-only in the proxy** (the same `location ~ ^/api/(devices/pair-request|phone/call-event)` block in `nginx-proxy/nginx.conf` and `install.sh`) with an optional `caller_id.secret`; calls are logged (`phone_calls`), matched on the server (Greek number rules) and published as `call_incoming` to users with `caller_id.use` and to the counter screens. There is no public call socket any more |
+25
View File
@@ -0,0 +1,25 @@
# Third-party software shipped in the backend image
Xenia POS's own code is not covered by this file. It lists separate programs that are shipped
inside the backend image and run by it as separate processes.
## FFmpeg
- **What it does here:** makes the still frame and the screen-friendly version of uploaded
videos (`services/video.py`, plan step 5.4e). The backend starts it as a separate program and
reads its output; nothing of FFmpeg is linked into Xenia's code.
- **Where it comes from:** the `imageio-ffmpeg` Python package, version pinned in
`requirements.txt` (0.8.1). The package carries one static FFmpeg build per platform
(Linux x86-64 / ARM64: FFmpeg 9.0.2 built by the imageio project from the BtbN FFmpeg-Builds
scripts; Windows: the gyan.dev "essentials" build). Inside the image the program is at
`/usr/local/lib/python3.12/site-packages/imageio_ffmpeg/binaries/`.
- **Licence:** FFmpeg is free software under the **GNU General Public License, version 3 or
later** (built with `--enable-gpl --enable-version3`, no non-free parts). It includes x264
(GPL v2 or later) and other libraries under the GPL / LGPL. The full licence text:
<https://www.gnu.org/licenses/gpl-3.0.txt>. `ffmpeg -L` prints the licence of the build.
- **Source code:** FFmpeg: <https://ffmpeg.org/download.html> (git tag `n9.0.2`). Build scripts:
<https://github.com/BtbN/FFmpeg-Builds> and <https://github.com/imageio/imageio-ffmpeg>.
On request we provide the exact corresponding source of the FFmpeg build shipped with any
Xenia POS release, for at least three years after that release.
- **The package around it** (`imageio-ffmpeg`): BSD 2-Clause licence,
Copyright (c) 2019-2025, imageio.
+20
View File
@@ -281,6 +281,25 @@ def _loop() -> None:
_wake.clear()
def requeue_missing(db=None) -> int:
"""Videos marked done whose still frame is missing (a restore without all of data/media):
made again. → how many."""
from database import SessionLocal
from models.media import Media
own = db is None
db = db or SessionLocal()
try:
n = 0
for m in db.query(Media).filter(Media.kind == "video", Media.processing == "done"):
if store.original_path(m.sha256) and not os.path.exists(store.variant_path(m.sha256, "thumb")):
m.processing, n = "waiting", n + 1
db.commit()
return n
finally:
if own:
db.close()
def start_worker() -> None:
"""main.py: one background thread. With no tool, waiting videos are just played as uploaded."""
if not available():
@@ -295,6 +314,7 @@ def start_worker() -> None:
db.close()
logger.warning("video versions: no ffmpeg on this server; videos play as uploaded")
return
requeue_missing()
threading.Thread(target=_loop, daemon=True, name="video-versions").start()
logger.info("video versions: worker started (%s)", ffmpeg())
+12
View File
@@ -154,3 +154,15 @@ def test_a_mov_is_taken_as_a_video(client, owner_h, media_dir):
m = up(client, owner_h, data, name="IMG_1.MOV", ctype="video/quicktime").json()
assert (m["kind"], m["content_type"], m["duration_ms"]) == ("video", "video/quicktime", 12500)
assert m["urls"]["original"].endswith("/original")
@needs_tool
def test_after_a_partial_restore_a_video_is_prepared_again(client, db, owner_h, media_dir, tmp_path):
m = up(client, owner_h, tv_video(tmp_path), name="ready.mp4", ctype="video/mp4").json()
video.process_next(db)
folder = os.path.join(str(media_dir), m["sha256"][:2], m["sha256"])
for n in ("thumb.webp", "card.webp", "full.webp"):
os.remove(os.path.join(folder, n))
assert video.requeue_missing(db) == 1 and video.process_next(db) is True
assert set(client.get(f"/api/media/{m['id']}", headers=owner_h).json()["urls"]) == {"original", "thumb", "card", "full"}
assert video.requeue_missing(db) == 0
+1 -1
View File
@@ -82,7 +82,7 @@ try {
// 5.4e: the backend image carries the video tool: a phone video gets its version for screens
const ff = execFileSync('python', ['-c', 'import imageio_ffmpeg as i; print(i.get_ffmpeg_exe())'], { encoding: 'utf8' }).trim()
const hevc = execFileSync(ff, ['-hide_banner', '-loglevel', 'error', '-f', 'lavfi', '-i', 'testsrc2=s=2560x1440:r=25:d=2', '-c:v', 'libx265',
'-x265-params', 'log-level=error', '-tag:v', 'hvc1', '-f', 'mov', '-movflags', 'frag_keyframe+empty_moov', 'pipe:1'], { maxBuffer: 64 << 20 })
'-x265-params', 'log-level=error', '-tag:v', 'hvc1', '-metadata', `comment=${Date.now()}`, '-f', 'mov', '-movflags', 'frag_keyframe+empty_moov', 'pipe:1'], { maxBuffer: 64 << 20 })
const vf = new FormData()
vf.append('file', new Blob([hevc], { type: 'video/quicktime' }), 'IMG_0001.MOV')
const vid = await (await fetch(`${M}/api/media`, { method: 'POST', headers: { Authorization: `Bearer ${token}` }, body: vf })).json()