mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-05 06:28:26 +01:00
* feat(media): keep pictures in the private R2 bucket, drain them out of Postgres The owner's rule: pictures live in Cloudflare R2, not in Postgres or on the box's disk, and the database gets cleaned up. - src/lib/media/r2.ts: a small S3 client for R2, SigV4 by hand (node:crypto + fetch, no SDK), on the fleet's PHOTOS_S3_* names. Everything is private: MEDIA_PRIVATE_S3_BUCKET, or private/loki/ in the photos bucket. Unset means behaviour exactly as before. - Chat pictures and report screenshots are written to the bucket when it is configured; the row keeps the key (additive migration 0140: nullable object_key and screenshot_keys). Reads try the bucket, then the old column. A write the bucket refuses stays in Postgres, so nothing is lost. - A throttled drain started from instrumentation moves what Postgres still holds (chat images, report screenshots, executed commands' attachments): small batches under a transaction-scoped advisory lock, upload, HEAD to verify length/type/MD5, then key-and-null in one statement; error backoff, IMAGE_DRAIN=0 kill switch, progress on /api/health under `media`. - Commands that have not run keep their base64: runners hold no bucket credentials. Retry puts moved bytes back before re-sending. - Bot shots, private tile shots and preview pictures go to the bucket when configured, the temp folder otherwise; bucket caches keep their age limits. - Deleting a chat or an account deletes its objects by prefix. - Dropping the emptied columns stays a manual step (apply-schema.sh refuses DROP COLUMN): docs/infrastructure/media-storage.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmvb6xi489TfZMg7n9T * fix(media): private pictures only in MEDIA_PRIVATE_S3_BUCKET, never the photos bucket The photos bucket (fleet-media) gets a public domain, so a private Loki picture must never fall back into it. The private store now needs MEDIA_PRIVATE_S3_BUCKET; unset, or equal to PHOTOS_S3_BUCKET, counts as unconfigured: pictures stay in Postgres as today, the drain does not run, and the env check warns in one line. 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>