Files
solon/scripts
CatoandClaude Opus 5.5 5b8fac2fa7 Photos straight from Cloudflare R2; the box does no image work (#620)
* feat(photos): serve photographs straight from R2, no image work on the box

With NEXT_PUBLIC_MEDIA_BASE set at build time, the app box sends no
photograph bytes and resizes nothing; unset, everything is as before.

- src/lib/media: self-contained pipeline (no app imports, for a later move
  into @bitbaum/sitekit alongside Heidi's copy). media:render renders the
  bundled photographs at 640/960/1280/1920/2560 as AVIF and WebP with
  sharp and writes a committed manifest; media:upload (dry run by default,
  idempotent, immutable Cache-Control) sends them to the PHOTOS_S3_* bucket.
  A custom next/image loader, switched on only when the base is set, names
  the nearest variant; MediaImage draws AVIF with a WebP fallback and keeps
  the blur placeholder. ThemedPhoto, the menu feature and the ideas page
  use it. A test fails while the manifest lags an original.
- Place photographs: with a base set, photoUrl points at the bucket object
  (place-photos/<file>@<width>) instead of /api/place-photo, which stays
  for the fallback and for PLACE_PHOTOS_VIA_APP=1 while the bucket fills.
  places:photos:to-r2 is now dry run by default; --apply copies what is
  only in place_photo_bytes and reads the rest of the shown widths from
  Commons straight into the bucket. Nothing is dropped.
- places:photos:warm checks the bucket first and only falls back to the
  route for a miss.
- .env.example and AGENTS.md document the variables and the order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmvb6xi489TfZMg7n9T

* feat(photos): the box's build fills the bucket and switches it on itself

Nobody runs manual steps on the box, so `pnpm run build` now starts with
scripts/media-ensure.ts. On the box's build (SELF_HOST=1, or MEDIA_ENSURE=1)
with PHOTOS_S3_* and MEDIA_PUBLIC_BASE set, it HEADs every manifest variant,
renders (sharp, concurrency 1, no cache) and uploads only the missing ones,
reads one back through the public base, and only on a 200 with the image's
content type writes NEXT_PUBLIC_MEDIA_BASE into .env.production.local
(gitignored) for next build. Anything missing or failing is one log line,
takes back a base an earlier build wrote, and exits 0: the build never
fails because of media. An explicit NEXT_PUBLIC_MEDIA_BASE still overrides.

Place photographs stay on /api/place-photo by default (it copies DB-only
photographs into the bucket on first request); PLACE_PHOTOS_DIRECT=1 is
the later, explicit switch to direct addresses.

The decision logic (src/lib/media/ensure.ts) is pure and tested; sharp's
settings are shared by media:render and the build. AGENTS.md and
.env.example: an operator only gives the bucket a public domain and puts
the five variables in /opt/fleet/env.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmvb6xi489TfZMg7n9T

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-26 12:53:30 +01:00
..