M7: hardening and final pass

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
lucioandClaude Opus 5.5 committed 2026-11-04 05:10:46 -08:00
1 parent 00ee2a6d12
commit ae898a2787
30 files changed
+878 -107

No files matched your search

+7 -7
View File
@@ -11,7 +11,7 @@ uploads (rsync/SFTP) -> /srv/luphoto/albums -> watcher (debounce) -> processor (
-> serve mode (built-in HTTP) or export mode (folder for Caddy/nginx) -> Cloudflare Tunnel + cache -> browser canvas stitches visible tiles
```
- Commands: `luphoto build` runs once; `luphoto serve` builds, watches and serves; `luphoto export` builds into the output folder and keeps watching. `-config` flag, default `/etc/luphoto/config.toml`.
- Commands: `luphoto build` runs once; `luphoto serve` builds, watches and serves; `luphoto export` builds into the output folder and keeps watching; `luphoto run` does `serve` or `export` as `server.mode` says (the systemd unit uses it); `luphoto version`. `-config` flag, default `/etc/luphoto/config.toml`. Rebuilds never overlap: changes during a build cause one follow-up build.
- Tiling with libvips CLI (`vips`), installed by `apt install libvips-tools`. Support libvips 8.12 (Ubuntu 22.04) and 8.15 (Ubuntu 24.04): metadata stripping is `strip` on 8.12 and `keep=none` on 8.15+.
- Front-end: plain TypeScript, no framework, bundled with esbuild, embedded in the binary with `go:embed`. Fixed Lucio brand.
- Speed and memory matter: photos are processed in parallel by a bounded worker pool; hashing, EXIF reading and tile renaming run concurrently; the browser fetches tiles concurrently and decodes off the main thread.
@@ -47,7 +47,7 @@ uploads (rsync/SFTP) -> /srv/luphoto/albums -> watcher (debounce) -> processor (
- `cover.crop` is `[x, y, w, h]` in original pixels; or `cover.focus_y` (0–1) picks a 32:9 band at full width. Default: first photo, focus_y 0.5.
- `order` sorts ascending; albums without it sort newest `date` first, after ordered ones. `hidden: true` builds the album but leaves it off the index.
- Album slug = folder name. Captions are plain text with `*emphasis*` and line breaks only.
- A broken album.json makes the build skip that album and log why; the previous build stays live.
- A broken album.json makes the build skip that album and log why; the previous build's version of that album stays live (it is carried into the new build).
## Processing each photo
@@ -60,7 +60,7 @@ uploads (rsync/SFTP) -> /srv/luphoto/albums -> watcher (debounce) -> processor (
7. Tile paths: `/t/<photo-hash>/<tile-id>.webp`. photo-hash = first 16 hex of SHA-256 over the original bytes + a processing-settings fingerprint. tile-id = first 16 hex of HMAC-SHA-256(site key, photo-hash|level|x|y). The site key is generated once and kept in the state folder. On disk and in developer tools the tiles are an unordered pile of patches; only the manifest maps them back.
8. Album manifest `/a/<slug>/manifest.<build>.json`: per photo width, height, level sizes, tile grid per level, tile ids in row-major order per level, byte size of every tile, caption, title, alt, EXIF, slides, seed. Covers are pyramids too and are described in `/index.<build>.json`.
Incremental: a photo is reprocessed only when its photo-hash is new. Each build writes `builds/<id>/` (HTML, manifests, assets) next to a shared `t/` tile folder; the `current` symlink flips only when the build is complete. Keep the last `keep_builds` builds; delete tile folders no kept build references. Write everything to temporary names and rename, so readers never see partial files.
Incremental: a photo is reprocessed only when its photo-hash is new. Each build writes `builds/<id>/` (HTML, manifests, assets, `404.html`, and a `.gz` copy of every HTML, JSON, JS, CSS and SVG file for precompressed serving) next to a shared `t/` tile folder and a shared `og/` folder of 1200×630 Open Graph JPEGs cut around each album cover (the only non-tiled images; derived, small, metadata stripped); the `current` symlink flips only when the build is complete. Keep the last `keep_builds` builds; delete tile folders no kept build references. Write everything to temporary names and rename, so readers never see partial files.
Storage: about 1.33× the top level, roughly 6–10 MB of tiles per Z8 photo.
@@ -77,7 +77,7 @@ Moving to another photo aborts that photo's requests. Prefetch the next photo's
## Screens
Album index: full-width strips, 8 px apart on phones, 16 px on desktop. Header with the Lucio wordmark (Guoliang → Lucio morph on hover, the only animation on this screen); footer with the chop. Closed strip 32:6 showing the `collapsed_focus_y` band of the 32:9 cover, height `min(100vw*6/32, 28vh)`; open 32:9, height `min(100vw*9/32, 62vh)`; wider screens crop left/right, never stretch. Desktop: hover opens. Touch: the strip nearest the vertical centre opens while scrolling; tap enters. On open the height animates 240 ms, then the title fades in (light-on): mono date line, then the title in Bricolage Grotesque, bottom-left. Covers use the tile loader; closed strips load only the visible band; only strips near the viewport load.
Album index: full-width strips, 8 px apart on phones, 16 px on desktop. Header with the Lucio wordmark (Guoliang → Lucio morph on hover, the only animation on this screen); footer with the chop. Closed strip 32:6 showing the `collapsed_focus_y` band of the 32:9 cover, height `min(100vw*6/32, 28vh)`; open 32:9, height `min(100vw*9/32, 62vh)`; the cover is drawn cover-fit, never stretched (under the height caps a very wide screen crops top and bottom). Desktop: hover opens. Touch: the strip nearest the vertical centre opens while scrolling; tap enters. On open the height animates 240 ms, then the title fades in (light-on): mono date line, then the title in Bricolage Grotesque, bottom-left. Covers use the tile loader; closed strips load only the visible band; only strips near the viewport load.
Album viewer: one photo at a time, contained in the viewport (fills height or width, never stretched), centred on graphite. Swipe right-to-left, ←/→, click-and-drag; one pointer-events handler for mouse and touch with flick velocity and rubber-band ends; Home/End; Esc returns to the index. `slides: N`: the photo is scaled so a 1/N-wide section fits the viewport; moving between its slides is a continuous pan. `/a/<slug>/#7` opens photo 7. End card: chop, "— Lucio", the next album's strip. Reduced motion: crossfades.
@@ -87,7 +87,7 @@ Lucio brand (source of truth: ../LUCIO_ip): graphite #111114 ground, paper #F3F1
## Discouraging saves
No `<img>` for photos, only canvas. Output never contains an original. Right-click, drag, selection and long-press callouts are disabled. Hashed tile names (above). Optional `scramble_cells` (off): shuffle 64 px cells inside each tile with a per-photo key and reorder when drawing. Hotlink: Referer check on `/t/*` in the built-in server and the Caddy/nginx examples.
No `<img>` for photos, only canvas. Output never contains an original. Right-click, drag, selection and long-press callouts are disabled. Hashed tile names (above). Optional `scramble_cells` (off): shuffle the full 64 px cells inside each tile with a per-photo key (HMAC of the site key and photo-hash, then a seeded Fisher–Yates per tile; tile overlap is 0 when on); the client restores each tile once when it decodes it, before it is cached and drawn. Hotlink: Referer check on `/t/*` in the built-in server and the Caddy/nginx examples; an empty Referer and the site's own host are allowed.
## Config `/etc/luphoto/config.toml`
@@ -128,14 +128,14 @@ block_context_menu = true
hotlink_allow = ["photos.luciochen.com"]
```
Defaults when a path is missing: running as root or under systemd uses `/var/lib/luphoto/site` and `/var/cache/luphoto`; otherwise `$XDG_DATA_HOME/luphoto/site` and `$XDG_CACHE_HOME/luphoto` (Go `os.UserCacheDir` equivalents). The site key lives in the state folder next to the output. SIGHUP re-reads the config and rebuilds. The watcher ignores `.part`, `.tmp`, dotfiles and rsync temp names.
Defaults when a path is missing: running as root or under systemd uses `/var/lib/luphoto/site` and `/var/cache/luphoto`; otherwise `$XDG_DATA_HOME/luphoto/site` and `$XDG_CACHE_HOME/luphoto` (Go `os.UserCacheDir` equivalents). The site key and the per-photo processing records live in the state folder (`state/`) next to the output. SIGHUP re-reads the config and rebuilds. The watcher ignores `.part`, `.tmp`, dotfiles and rsync temp names.
## Deployment
- `.deb` via nfpm: binary, `/etc/luphoto/config.toml`, systemd unit, `luphoto` user, `/srv/luphoto/albums`. Depends on `libvips-tools`. Ubuntu 22.04/24.04, Debian 12; other distros: tarball + unit file.
- systemd: read-only albums, read-write output and cache only, NoNewPrivileges, ProtectSystem=strict.
- Cloudflare Tunnel; cache rule `/t/*` for a month; HTML and manifests short TTL; manifests are build-named, so no purging.
- Caddy (export): root `/var/lib/luphoto/site/current`, `/t/*` `public, max-age=31536000, immutable`, `/a/*` `max-age=60`, CSP `default-src 'self'; img-src 'self' blob: data:; frame-ancestors 'none'`, hotlink 403 on `/t/*`. Serve mode: `reverse_proxy 127.0.0.1:8080`, the built-in server sends the same headers. nginx equivalent provided.
- Caddy (export): root `/var/lib/luphoto/site/current`, `/t/*` `public, max-age=31536000, immutable`, `/a/*` `max-age=60`, `/og/*` and `/assets/*` immutable too, HTML and index JSON `max-age=60`, CSP `default-src 'self'; img-src 'self' blob: data:; font-src 'self'; worker-src 'self'; frame-ancestors 'none'`, `nosniff`, `Referrer-Policy: strict-origin-when-cross-origin`, hotlink 403 on `/t/*`, precompressed gzip, no directory listings, `404.html` for missing paths, GET/HEAD only. Serve mode: `reverse_proxy 127.0.0.1:8080`, the built-in server sends the same headers. nginx equivalent provided.
## Milestones