@@ -9,20 +9,27 @@ export default class StorageBucketApi {
9
9
protected headers : { [ key : string ] : string }
10
10
protected fetch : Fetch
11
11
12
- constructor ( url : string , headers : { [ key : string ] : string } = { } , fetch ?: Fetch ) {
12
+ constructor (
13
+ url : string ,
14
+ headers : { [ key : string ] : string } = { } ,
15
+ fetch ?: Fetch ,
16
+ opts ?: { useNewHostname ?: boolean }
17
+ ) {
13
18
const baseUrl = new URL ( url )
14
19
15
20
// if legacy uri is used, replace with new storage host (disables request buffering to allow > 50GB uploads)
16
21
// "project-ref.supabase.co/storage/v1" becomes "project-ref.storage.supabase.co/v1"
17
- const isSupabaseHost = / s u p a b a s e \. ( c o | i n | r e d ) $ / . test ( baseUrl . hostname )
18
- const legacyStoragePrefix = '/storage'
19
- if (
20
- isSupabaseHost &&
21
- ! baseUrl . hostname . includes ( 'storage.supabase.' ) &&
22
- baseUrl . pathname . startsWith ( legacyStoragePrefix )
23
- ) {
24
- baseUrl . pathname = baseUrl . pathname . substring ( legacyStoragePrefix . length )
25
- baseUrl . hostname = baseUrl . hostname . replace ( 'supabase.' , 'storage.supabase.' )
22
+ if ( opts ?. useNewHostname ) {
23
+ const isSupabaseHost = / s u p a b a s e \. ( c o | i n | r e d ) $ / . test ( baseUrl . hostname )
24
+ const legacyStoragePrefix = '/storage'
25
+ if (
26
+ isSupabaseHost &&
27
+ ! baseUrl . hostname . includes ( 'storage.supabase.' ) &&
28
+ baseUrl . pathname . startsWith ( legacyStoragePrefix )
29
+ ) {
30
+ baseUrl . pathname = baseUrl . pathname . substring ( legacyStoragePrefix . length )
31
+ baseUrl . hostname = baseUrl . hostname . replace ( 'supabase.' , 'storage.supabase.' )
32
+ }
26
33
}
27
34
28
35
this . url = baseUrl . href
0 commit comments