Anti-scraping: 3x3 grids, decoy pools, robot check
Every pyramid level is cut into at least min_grid x min_grid tiles. Each photo's tile pool mixes real tiles with hard-linked decoys from other photos; the grid-to-pool map, byte sizes, seed and scramble seed are sealed per build and unlocked by a press-and-hold check backed by a static proof of work. Cell scrambling is on by default, and robots.txt disallows tiles and pool files. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
aaf7cafdf9
commit
f5152fb709
30 files changed
+2136
-203
No files matched your search
+28
-11
@@ -1,8 +1,8 @@
|
||||
# LuPhoto design
|
||||
|
||||
LuPhoto serves photos.luciochen.com. It is one Go program that reads album folders from disk, cuts every photo into fixed 512 px tiles at several resolutions, and publishes a fully static, Lucio-branded site that a browser stitches back together on a canvas. No editing, comments, likes, themes, templating or camera RAW support.
|
||||
LuPhoto serves photos.luciochen.com. It is one Go program that reads album folders from disk, cuts every photo into tiles of at most 512 px (at least 3 × 3 per level) at several resolutions, and publishes a fully static, Lucio-branded site that a browser stitches back together on a canvas. No editing, comments, likes, themes, templating or camera RAW support.
|
||||
|
||||
Decisions: name LuPhoto (binary, user and paths lowercase `luphoto`), Go, no resolution cap, hashed tile names in v1, cell scrambling optional and off, JPEGs not listed in album.json are hidden.
|
||||
Decisions: name LuPhoto (binary, user and paths lowercase `luphoto`), Go, no resolution cap, hashed tile names in v1, cell scrambling on by default, decoy tiles and a sealed tile map behind a one-time robot check, JPEGs not listed in album.json are hidden.
|
||||
|
||||
## Architecture
|
||||
|
||||
@@ -53,20 +53,29 @@ uploads (rsync/SFTP) -> /srv/luphoto/albums -> watcher (debounce) -> processor (
|
||||
|
||||
1. Autorotate by EXIF orientation, convert to sRGB from the embedded profile.
|
||||
2. Read camera, lens, focal length, aperture, shutter, ISO and date into the manifest. Drop everything else, including GPS. Tiles carry no metadata.
|
||||
3. Pyramid: tiles 512 px, 1 px overlap; each level halves the previous one until the long edge is under 100 px. Level 0 is the smallest.
|
||||
3. Pyramid: each level halves the previous one until the long edge is under 100 px (at least `min_levels` levels), but never below a short edge of `min_grid` px. Level 0 is the smallest. Each level has its own tile size, min(`tile_size` 512, ⌊short edge ÷ `min_grid` 3⌋), at least 1 px, so every level is a grid of at least 3 × 3 tiles; covers (32:9) are usually 11 × 3 at every level. Overlap 1 px, 0 when the tile is at most twice the overlap and always 0 with cell scrambling. `dzsave` cuts one level at a time with that level's tile size.
|
||||
4. WebP by default (AVIF optional); WebP tiles and the seed are saved with `smart_subsample` so chroma stays sharp. Quality per level: `top` for the top two levels, `low` for levels whose long edge is at most 1100 px, `mid` otherwise.
|
||||
5. Seed: a 48 px (long edge) WebP, base64 inside the album manifest.
|
||||
5. Seed: a 48 px (long edge) WebP, kept in the per-photo record and published only inside the sealed payload.
|
||||
6. No resolution cap: the full-resolution level is stored; the loader never fetches beyond screen size × max_dpr.
|
||||
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`.
|
||||
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 (which includes `min_grid` and `scramble_cells`). 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. Each folder also holds decoys (below), so on disk and in developer tools a folder is an unordered pile of patches from many photos.
|
||||
8. Album manifest `/a/<slug>/manifest.<build>.json`: layout only. Per photo width, height, per level width, height, tile size, cols, rows (and overlap when not 0), caption, title, alt, EXIF, slides, plus the build's `gate` record. Covers are pyramids too and are described in `/index.<build>.json`. Tile ids, byte sizes, the seed and the scramble seed are not in it.
|
||||
|
||||
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.
|
||||
Incremental: a photo is reprocessed only when its photo-hash is new. Each build writes `builds/<id>/` (HTML, manifests, per-photo pool files, assets, `404.html`, `robots.txt`, `.refs`, 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, and inside live folders delete files no kept build's `.refs` lists. Write everything to temporary names and rename, so readers never see partial files (pool files are written straight into the unpublished stage folder).
|
||||
|
||||
Storage: about 1.33× the top level, roughly 6–10 MB of tiles per Z8 photo.
|
||||
Storage: about 1.33× the top level, roughly 6–10 MB of tiles per Z8 photo. Decoys are hard links and cost directory entries, not bytes; small low-level tiles cost some filesystem block overhead.
|
||||
|
||||
## Protection step (per build, after all photos are processed)
|
||||
|
||||
1. Gate: random 16-byte salt and random n < 2^`pow_bits`. Key s = SHA-256("luphoto-key" | salt | n as 4 bytes big-endian). Published in the index and every manifest: `{build, salt, bits, check}` with check = first 16 bytes of SHA-256("luphoto-check" | salt | n). With `gate = false`: `{build, key}` and no robot check, same code path.
|
||||
2. Decoys: all live pyramids (photos and covers of every published album, carried albums included) are indexed by tile size; each pyramid's primary album is the first album, in index order, that uses it. For each level with R real tiles, `decoys` × R slots are filled from the bucket whose tile size is closest to the level's, taking candidates from other albums first, then other photos of the same album, then (single-pyramid site only) the photo itself. A slot's source is the next tile on a ring ordered by tile id after a target drawn from a PRNG keyed by HMAC(site key, "pick"|hash|level), skipping ineligible or already used tiles, so selections are stable while the site does not change. Decoy name = first 16 hex of HMAC-SHA-256(site key, "decoy"|photo-hash|level|slot|source tile id). The file is a hard link to the source tile (a copy if linking fails); names already present in the folder are reused (one `ReadDir` per folder).
|
||||
3. Pool: per level the real ids and decoy names, shuffled with a PRNG keyed by HMAC(site key, "pool"|hash|level), written as one string of 16-hex ids.
|
||||
4. Seal: plaintext = "luphoto-sealed-1" (16 bytes) + JSON `{seed, scramble, levels: [{map, bytes}]}` where `map` turns a row-major grid index into a pool index. Ciphertext = plaintext XOR keystream, block i = SHA-256(s | nonce | i as 4 bytes big-endian), 12-byte random nonce in front, base64.
|
||||
5. `/a/<slug>/p/<hash>.<build>.json` = `{levels: [pool strings], sealed}` for every photo and the cover of each album; build-named like the manifests, so a new build never pairs with a cached pool. `builds/<id>/.refs` lists every pool id per folder (8-byte binary) for the cleanup.
|
||||
|
||||
## Loading in the browser
|
||||
|
||||
1. Seed (≈0 ms): the manifest is loaded; draw the seed scaled and blurred.
|
||||
0. Gate: if the gate is on and `localStorage` has no pass for this build, the robot-check card is shown at once and a Web Worker (the tile worker script, a separate instance) brute-forces n with an allocation-free SHA-256 (midstate of the first 7 rounds and the constant schedule words precomputed). Each photo's pool file is fetched when the photo or cover is near. Until unlocked, or when a pool cannot be opened, the photo shows its probe level filled with random pool entries drawn into the grid cells (one fetch per cell at most). After unlocking, pools are decrypted lazily on the main thread (a few hundred SHA-256 blocks per photo), the seed fades in over the jumble, and the real tiles follow as below.
|
||||
1. Seed: draw the seed scaled and blurred.
|
||||
2. Needed level: smallest level whose width ≥ displayed width × min(devicePixelRatio, max_dpr).
|
||||
3. Probe: fetch 1–2 tiles of the level about 1/8 of the needed one; measure throughput; blend with earlier measurements kept in sessionStorage.
|
||||
4. Final level: highest level up to the needed one whose visible-tile bytes ÷ throughput ≤ (budget − elapsed) × 0.8. If it is 2+ levels above the probe, fetch one intermediate level first.
|
||||
@@ -87,7 +96,11 @@ 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 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.
|
||||
No `<img>` for photos, only canvas. Output never contains an original. Right-click, drag, selection and long-press callouts are disabled. Hashed tile names, at least 3 × 3 tiles per level, decoys and sealed maps behind the robot check (above). `scramble_cells` (on by default): 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; tiles under two cells wide or high are left alone; tile overlap is 0 when on); the scramble seed travels only inside the sealed payload, and 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. `robots.txt` disallows `/t/` and `/a/*/p/`.
|
||||
|
||||
Robot check card (index and album pages, only without a pass for the current build): graphite-2 card, mono eyebrow "Photos · Lucio", the line "Press and hold to see the photos" in Bricolage Grotesque, and an 88 px round button with a beam progress ring. Holding for 900 ms (pointer, or Space/Enter while focused) completes it; releasing early resets the ring. If the worker is still searching, the ring turns indeterminate until it finishes. The rest of the page is `inert` while the card is up; focus starts on the button and returns to the page afterwards. The pass `{build, s}` is kept in `localStorage` (memory if storage is blocked); a pass that fails to open a pool is dropped and the card comes back. Reduced motion: no spin, no fade.
|
||||
|
||||
Limits: this raises the cost of bulk downloading; it cannot stop a scraper that drives a real browser or reimplements the client, and decoys are byte-identical to tiles of other photos, so crawling every folder reveals which files are shared.
|
||||
|
||||
## Config `/etc/luphoto/config.toml`
|
||||
|
||||
@@ -110,7 +123,8 @@ quality = { top = 90, mid = 88, low = 88 }
|
||||
min_levels = 6
|
||||
seed_px = 48
|
||||
tile_names = "hashed"
|
||||
scramble_cells = false
|
||||
scramble_cells = true
|
||||
min_grid = 3
|
||||
|
||||
[loading]
|
||||
budget_ms = 3000
|
||||
@@ -126,6 +140,9 @@ keep_builds = 3
|
||||
[protection]
|
||||
block_context_menu = true
|
||||
hotlink_allow = ["photos.luciochen.com"]
|
||||
decoys = 4
|
||||
gate = true
|
||||
pow_bits = 20
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
Reference in new issue
Block a user