feat(attachments): R2 toggle, storage metrics, and demo R2 config

Add an ATTACHMENTS_ENABLED switch (default on when R2 is bound) via a
central getAttachmentBucket helper, surface R2 + estimated KV usage
against the free tier on the status page and /api/stats (refreshed by the
hourly cron), let setup.sh create and wire the R2 bucket, and bind the
demo bucket so the deployed demo has attachments.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Julien Herr
2026-05-23 17:33:50 +02:00
parent 7226e718f7
commit f150d40c45
19 changed files with 387 additions and 23 deletions
+4 -2
View File
@@ -1,8 +1,10 @@
import { Context } from "hono";
import { Env } from "../types";
import { getAttachmentBucket } from "../utils/attachments";
export async function handle(c: Context<{ Bindings: Env }>): Promise<Response> {
if (!c.env.ATTACHMENT_BUCKET) {
const bucket = getAttachmentBucket(c.env);
if (!bucket) {
return new Response("Attachment storage not configured", { status: 404 });
}
@@ -13,7 +15,7 @@ export async function handle(c: Context<{ Bindings: Env }>): Promise<Response> {
return new Response("Not found", { status: 404 });
}
const object = await c.env.ATTACHMENT_BUCKET.get(attachmentId);
const object = await bucket.get(attachmentId);
if (!object) {
return new Response("Not found", { status: 404 });