Files
orangecat/scripts/storage/setup-storage-buckets.js
Your NameandClaude 2872828779 chore: version 0.1.1 deployment - fix configuration and dependencies
- Bump version to 0.1.1 for tracking
- Add webpack-bundle-optimizer script for Next.js config
- Simplify ESLint configuration to resolve missing dependencies
- Prepare for production deployment with proper version control

This deployment includes:
- Profile update fixes with banner_url support
- LN address validation
- Auth cookie fixes for profile updates
- Various documentation and testing improvements

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-13 09:30:45 +02:00

109 lines
3.4 KiB
JavaScript

#!/usr/bin/env node
/**
* Setup Supabase Storage Buckets for OrangeCat
* Creates the necessary storage buckets for avatar and banner uploads
*/
const { createClient } = require('@supabase/supabase-js')
require('dotenv').config()
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL
const supabaseServiceKey = process.env.SUPABASE_SERVICE_ROLE_KEY
if (!supabaseUrl || !supabaseServiceKey) {
console.error('Missing required environment variables:')
console.error('- NEXT_PUBLIC_SUPABASE_URL')
console.error('- SUPABASE_SERVICE_ROLE_KEY')
process.exit(1)
}
const supabase = createClient(supabaseUrl, supabaseServiceKey)
async function setupStorageBuckets() {
console.log('🪣 Setting up Supabase Storage Buckets...')
try {
// Create avatars bucket
console.log('Creating avatars bucket...')
const { data: avatarsData, error: avatarsError } = await supabase.storage.createBucket('avatars', {
public: true,
allowedMimeTypes: ['image/jpeg', 'image/png', 'image/webp', 'image/gif'],
fileSizeLimit: 5242880, // 5MB
})
if (avatarsError && !avatarsError.message.includes('already exists')) {
console.error('Error creating avatars bucket:', avatarsError)
} else {
console.log('✅ Avatars bucket ready')
}
// Create banners bucket
console.log('Creating banners bucket...')
const { data: bannersData, error: bannersError } = await supabase.storage.createBucket('banners', {
public: true,
allowedMimeTypes: ['image/jpeg', 'image/png', 'image/webp', 'image/gif'],
fileSizeLimit: 10485760, // 10MB
})
if (bannersError && !bannersError.message.includes('already exists')) {
console.error('Error creating banners bucket:', bannersError)
} else {
console.log('✅ Banners bucket ready')
}
// Set up bucket policies
console.log('Setting up bucket policies...')
// Avatars bucket policy
const { error: avatarsPolicyError } = await supabase.rpc('create_policy', {
table_name: 'objects',
policy_name: 'Users can upload their own avatars',
definition: `
(bucket_id = 'avatars'::text) AND
(auth.uid()::text = (storage.foldername(name))[1])
`,
action: 'INSERT'
})
const { error: avatarsSelectPolicyError } = await supabase.rpc('create_policy', {
table_name: 'objects',
policy_name: 'Avatar images are publicly accessible',
definition: `bucket_id = 'avatars'::text`,
action: 'SELECT'
})
// Banners bucket policy
const { error: bannersPolicyError } = await supabase.rpc('create_policy', {
table_name: 'objects',
policy_name: 'Users can upload their own banners',
definition: `
(bucket_id = 'banners'::text) AND
(auth.uid()::text = (storage.foldername(name))[1])
`,
action: 'INSERT'
})
const { error: bannersSelectPolicyError } = await supabase.rpc('create_policy', {
table_name: 'objects',
policy_name: 'Banner images are publicly accessible',
definition: `bucket_id = 'banners'::text`,
action: 'SELECT'
})
console.log('✅ Storage bucket setup complete!')
console.log('\nBuckets created:')
console.log('- avatars (5MB limit, public)')
console.log('- banners (10MB limit, public)')
} catch (error) {
console.error('❌ Error setting up storage buckets:', error)
process.exit(1)
}
}
if (require.main === module) {
setupStorageBuckets()
}
module.exports = { setupStorageBuckets }