mirror of
https://github.com/supabase/supabase.git
synced 2026-05-11 19:26:38 +08:00
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Logo field now accepts/editable logo URL, plus a new storage-based Logo Picker to select or remove images from project storage. * Full storage picker: browse buckets, columns/list views, search, drag‑and‑drop uploads, file previews (image/audio/video), and single-file selection with responsive mobile/desktop layouts. * **Refactor** * Logo submission streamlined to send the provided URL directly (legacy file-read/upload flow removed). <!-- end of auto-generated comment: release notes by coderabbit.ai -->
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import { QueryClient } from '@tanstack/react-query'
|
|
import { toast } from 'sonner'
|
|
|
|
import { storageKeys } from '@/data/storage/keys'
|
|
import { createProjectSupabaseClient } from '@/lib/project-supabase-client'
|
|
|
|
export async function uploadFilesToBucket({
|
|
files,
|
|
projectRef,
|
|
hostEndpoint,
|
|
bucketName,
|
|
bucketId,
|
|
currentPath,
|
|
queryClient,
|
|
}: {
|
|
files: File[]
|
|
projectRef: string
|
|
hostEndpoint: string
|
|
bucketName: string
|
|
bucketId: string
|
|
currentPath: string
|
|
queryClient: QueryClient
|
|
}) {
|
|
if (files.length === 0) return
|
|
|
|
const client = await createProjectSupabaseClient(projectRef, hostEndpoint)
|
|
let successCount = 0
|
|
|
|
for (const file of files) {
|
|
const filePath = currentPath ? `${currentPath}/${file.name}` : file.name
|
|
const { error } = await client.storage.from(bucketName).upload(filePath, file, { upsert: true })
|
|
if (error) {
|
|
toast.error(`Failed to upload ${file.name}: ${error.message}`)
|
|
} else {
|
|
successCount++
|
|
}
|
|
}
|
|
|
|
if (successCount > 0) {
|
|
toast.success(`Successfully uploaded ${successCount} file${successCount > 1 ? 's' : ''}`)
|
|
const queryKey = storageKeys.objects(projectRef, bucketId, '')
|
|
await queryClient.refetchQueries({ queryKey, type: 'active' })
|
|
}
|
|
}
|