Skip to content
This repository was archived by the owner on Oct 9, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/packages/StorageBucketApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,22 @@ export default class StorageBucketApi {
protected fetch: Fetch

constructor(url: string, headers: { [key: string]: string } = {}, fetch?: Fetch) {
this.url = url
const baseUrl = new URL(url)

// if legacy uri is used, replace with new storage host (disables request buffering to allow > 50GB uploads)
// "project-ref.supabase.co/storage/v1" becomes "project-ref.storage.supabase.co/v1"
const isSupabaseHost = /supabase\.(co|in|red)$/.test(baseUrl.hostname)
const legacyStoragePrefix = '/storage'
if (
isSupabaseHost &&
!baseUrl.hostname.includes('storage.supabase.') &&
baseUrl.pathname.startsWith(legacyStoragePrefix)
) {
baseUrl.pathname = baseUrl.pathname.substring(legacyStoragePrefix.length)
baseUrl.hostname = baseUrl.hostname.replace('supabase.', 'storage.supabase.')
}

this.url = baseUrl.href
this.headers = { ...DEFAULT_HEADERS, ...headers }
this.fetch = resolveFetch(fetch)
}
Expand Down
37 changes: 37 additions & 0 deletions test/storageBucketApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,43 @@ describe('Bucket API Error Handling', () => {
jest.restoreAllMocks()
})

describe('URL Construction', () => {
const urlTestCases = [
[
'https://blah.supabase.co/storage/v1',
'https://blah.storage.supabase.co/v1',
'update legacy prod host to new host',
],
[
'https://blah.supabase.red/storage/v1',
'https://blah.storage.supabase.red/v1',
'update legacy staging host to new host',
],
[
'https://blah.storage.supabase.co/v1',
'https://blah.storage.supabase.co/v1',
'accept new host without modification',
],
[
'https://blah.supabase.co.example.com/storage/v1',
'https://blah.supabase.co.example.com/storage/v1',
'not modify non-platform hosts',
],
[
'http://localhost:1234/storage/v1',
'http://localhost:1234/storage/v1',
'support local host with port without modification',
],
]

urlTestCases.forEach(([inputUrl, expectUrl, description]) => {
it('should ' + description, () => {
const storage = new StorageClient(inputUrl, { apikey: KEY })
expect(storage['url']).toBe(expectUrl)
})
})
})

describe('listBuckets', () => {
it('handles network errors', async () => {
const mockError = new Error('Network failure')
Expand Down