mirror of
https://github.com/supabase/supabase.git
synced 2026-05-09 10:19:50 -04:00
c7f653f33f
## 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 -->
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { env } from "../../env.config.js";
|
|
|
|
/**
|
|
* Make an HTTP request to the local Supabase Storage API.
|
|
*
|
|
* @param path - The path to append to the storage base URL (e.g., '/bucket')
|
|
* @param options - Optional method and body
|
|
* @returns Parsed JSON response
|
|
* @throws Error if the request fails
|
|
*/
|
|
export async function storageRequest<T>(
|
|
path: string,
|
|
options?: { method?: 'GET' | 'POST' | 'PUT' | 'DELETE'; body?: Record<string, unknown> }
|
|
): Promise<T> {
|
|
const storageUrl = `${env.API_URL}/storage/v1`
|
|
|
|
const headers: Record<string, string> = {
|
|
apikey: env.SERVICE_ROLE_KEY,
|
|
Authorization: `Bearer ${env.SERVICE_ROLE_KEY}`,
|
|
}
|
|
|
|
if (options?.body) {
|
|
headers['Content-Type'] = 'application/json'
|
|
}
|
|
|
|
const response = await fetch(`${storageUrl}${path}`, {
|
|
method: options?.method ?? 'GET',
|
|
headers,
|
|
body: options?.body ? JSON.stringify(options.body) : undefined,
|
|
})
|
|
|
|
if (!response.ok) {
|
|
const text = await response.text()
|
|
throw new Error(`Storage request failed (${response.status}): ${text}`)
|
|
}
|
|
|
|
const text = await response.text()
|
|
return text ? JSON.parse(text) : ({} as T)
|
|
}
|