mirror of
https://github.com/supabase/supabase.git
synced 2026-05-08 07:50:20 +08:00
## I have read the [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) file. YES ## What kind of change does this PR introduce? - Move storage tests to run in parallel - Updated utils to use env <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Improved test reliability by shifting storage bucket setup and cleanup from UI-based to API-backed operations. * Enhanced test isolation with streamlined prerequisite navigation steps. * **Chores** * Updated environment configuration to support dynamic API URL and service role key settings. * Refactored internal storage management utilities for improved maintainability. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
55 lines
1.4 KiB
TypeScript
55 lines
1.4 KiB
TypeScript
import { storageRequest } from './client.js'
|
|
|
|
interface Bucket {
|
|
id: string
|
|
name: string
|
|
public: boolean
|
|
}
|
|
|
|
/**
|
|
* List all storage buckets.
|
|
*/
|
|
export async function listBuckets(): Promise<Bucket[]> {
|
|
return storageRequest<Bucket[]>('/bucket')
|
|
}
|
|
|
|
/**
|
|
* Create a storage bucket. Idempotent — skips creation if the bucket already exists.
|
|
*
|
|
* @param name - Bucket name / id
|
|
* @param isPublic - Whether the bucket should be public (default: false)
|
|
*/
|
|
export async function createBucket(name: string, isPublic: boolean = false): Promise<void> {
|
|
const buckets = await listBuckets()
|
|
if (buckets.some((b) => b.id === name)) return
|
|
|
|
await storageRequest('/bucket', {
|
|
method: 'POST',
|
|
body: { id: name, name, public: isPublic },
|
|
})
|
|
}
|
|
|
|
/**
|
|
* Delete a storage bucket. Idempotent — empties the bucket first, then deletes it.
|
|
* No-ops if the bucket does not exist.
|
|
*
|
|
* @param name - Bucket name / id
|
|
*/
|
|
export async function deleteBucket(name: string): Promise<void> {
|
|
const buckets = await listBuckets()
|
|
if (!buckets.some((b) => b.id === name)) return
|
|
|
|
await storageRequest(`/bucket/${name}/empty`, { method: 'POST' })
|
|
await storageRequest(`/bucket/${name}`, { method: 'DELETE' })
|
|
}
|
|
|
|
/**
|
|
* Delete every storage bucket.
|
|
*/
|
|
export async function deleteAllBuckets(): Promise<void> {
|
|
const buckets = await listBuckets()
|
|
for (const bucket of buckets) {
|
|
await deleteBucket(bucket.id)
|
|
}
|
|
}
|