Commit Graph
4 Commits
Author SHA1 Message Date
Jasper VanandClaude Opus 4.8 f24c6e2021 feat(avatar): self-host avatars on R2 on Workers + fix avatar refresh/fallback (#468)
* fix(avatar): refresh session after change and show fallback on remove

Two avatar-display bugs surfaced post-#456:
- After uploading/removing an avatar the UI showed the old image until a full
  reload. refreshSession() now calls getSession({ disableCookieCache: true }) to
  re-read user.image past the 5-min session cookie cache, then
  $store.notify('$sessionSignal') so useSession() actually refetches and
  re-renders (an external endpoint never toggles better-auth's session signal).
- Removing an avatar left a blank circle: the conditional `{user.image && <AvatarImage>}`
  unmounts the radix Image, which keeps a stale "loaded" status so the Fallback
  stays hidden. Always render <AvatarImage src={user?.image ?? undefined}> so radix
  re-runs its loading status (src -> undefined => "error") and shows the initials.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* feat(avatar): self-host avatars on R2 when deployed on Workers

The image-upload gateway now branches per request on the AVATARS R2 binding:
- binding present (Cloudflare) -> upload straight to R2 (key `scope/id`, content
  type in R2 metadata, a content-hash `?v=` cache-buster) and return either an
  AVATARS_PUBLIC_URL (R2 custom domain) URL or a relative /api/avatar-blobs URL.
- binding absent (Node/Docker, or a Worker without it) -> the existing ZPan Cloud
  avatar service, unchanged.

Adds a public GET /api/avatar-blobs/:scope/:id route that streams the blob from
the AVATARS binding (so local miniflare, which gives R2 no public URL, can serve
avatars too). AVATARS_BINDING / R2BucketLike live in platform/interface so both
the adapter and the http route can use them without crossing the arch boundary.
wrangler.toml declares the AVATARS bucket (prod + staging).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* ci(deploy): provision the zpan-avatars R2 bucket + AVATARS_PUBLIC_URL

The AVATARS R2 binding added for self-hosted avatars needs the bucket to exist on
deploy. Mirror the resource-provisioning pattern (D1/Queue): create zpan-avatars if
missing, enable its managed public URL, and upsert AVATARS_PUBLIC_URL so prod serves
avatars straight from R2 (zero Worker egress). Without the secret the app still works
via its /api/avatar-blobs route.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* refactor(avatar): reuse the original PUBLIC_IMAGES bucket/binding/env names

Keep the same Cloudflare resource names as before #456 removed them so the existing
`zpan-public-images` bucket is reused (not orphaned) and the API token scopes still
apply: R2 binding PUBLIC_IMAGES, bucket zpan-public-images(-staging), public-URL
secret PUBLIC_IMAGES_URL. Pure rename of the AVATARS naming I'd introduced — no
behavior change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-20 02:05:09 -04:00
saltboandClaude Opus 4.7 bcb0b67872 feat(platform): add getBinding() for platform-native resources
Platform-native bindings (Cloudflare R2/D1/KV, Azure Storage contexts,
etc.) are not representable as strings, so getEnv() can't carry them.
Add a typed getBinding<T>() accessor: returns the binding on platforms
that support it, undefined on others.

Callers branch on the return — e.g. \`getBinding<R2Bucket>('PUBLIC_IMAGES')\`
will be defined on CF and undefined on Node/Docker, letting the same
code pick a runtime-appropriate path without platform-specific imports.

Used in the next commit to switch the public image upload flow to R2
binding on CF (zero-auth, zero-egress) while keeping the S3 fallback
for every other platform.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-22 22:56:35 -04:00
saltboandClaude Opus 4.6 d4b7891e7f refactor: migrate raw SQL to Drizzle query builder in services and routes
Replace all db.all(sql`...`) / db.run(sql`...`) calls with Drizzle's
type-safe query builder (select/insert/update/delete). Schema changes
now trigger TypeScript errors in queries, and column name typos are
caught at compile time.

- Unify Database type to BaseSQLiteDatabase for query builder compat
- Derive Matter/Storage types from schema via $inferSelect
- Use inArray() instead of manual sql.join() for IN clauses
- Net -90 lines across 9 files

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-10 00:51:45 -04:00
saltboandClaude Opus 4.6 310e4950b3 refactor: flatten monorepo to single-package CF Pages Functions structure
Replace pnpm workspace monorepo (packages/server, packages/web, packages/shared)
with a flat single-package layout following Hono's pages-stack pattern. Switch from
pnpm to npm and from Workers+Assets to CF Pages Functions deployment model.

- Move source: packages/server/src/ → server/, packages/web/src/ → src/, packages/shared/src/ → shared/
- Add functions/api/[[route]].ts as CF Pages Functions entry (replaces entry-cloudflare.ts)
- Update 22 import paths: server uses relative, web uses @shared/@server aliases
- Merge three package.json into one, switch to npm
- Update wrangler.toml: remove main/assets (Pages auto-detects functions/ dir)
- Add per-directory tsconfig.json for VS Code type resolution
- Simplify Dockerfile for flat layout
- Fix react-pdf CSS import path (dist/esm/ → dist/)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-10 00:27:38 -04:00