ai-chatbot/apps/editor/instrumentation.ts
Anton 94e5f37983
fix: create project-thumbnails bucket in instrumentation.ts (#118)
The thumbnail upload (uploadProjectThumbnail) writes to a
'project-thumbnails' storage bucket, but instrumentation.ts only
bootstrapped the 'avatars' bucket.  This caused:

  Upload failed: Bucket not found

Add the missing bucket creation with matching constraints (public,
10 MB limit, image/png only).  Also refactor the bucket-exists check
to use a Set so it scales cleanly as more buckets are added.

Co-authored-by: Anton Pascal <anton-pascal@users.noreply.github.com>
2026-02-25 12:22:10 -05:00

34 lines
1.1 KiB
TypeScript

export async function register() {
// Only run on the server
if (process.env.NEXT_RUNTIME === 'nodejs') {
const { createClient } = await import('@supabase/supabase-js')
const url = process.env.NEXT_PUBLIC_SUPABASE_URL
const key = process.env.SUPABASE_SERVICE_ROLE_KEY
if (!url || !key) return
const supabase = createClient(url, key)
const { data: buckets } = await supabase.storage.listBuckets()
const bucketNames = new Set(buckets?.map((b) => b.name))
if (!bucketNames.has('avatars')) {
await supabase.storage.createBucket('avatars', {
public: true,
fileSizeLimit: 5 * 1024 * 1024, // 5MB
allowedMimeTypes: ['image/png', 'image/jpeg', 'image/webp', 'image/gif'],
})
console.log('Created "avatars" storage bucket')
}
if (!bucketNames.has('project-thumbnails')) {
await supabase.storage.createBucket('project-thumbnails', {
public: true,
fileSizeLimit: 10 * 1024 * 1024, // 10MB (matches uploadProjectThumbnail validation)
allowedMimeTypes: ['image/png'],
})
console.log('Created "project-thumbnails" storage bucket')
}
}
}