Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix: update storage to use the new URL endpoint (#42974)

Ivan Vasilov554a91e1b2f3
diff --git a/apps/studio/csp.js b/apps/studio/csp.js
index c286aa55223..ff2f9f0a1db 100644
--- a/apps/studio/csp.js
+++ b/apps/studio/csp.js
@@ -5,7 +5,7 @@ const SUPABASE_URL = process.env.SUPABASE_URL ? new URL(process.env.SUPABASE_URL
const GOTRUE_URL = process.env.NEXT_PUBLIC_GOTRUE_URL
? new URL(process.env.NEXT_PUBLIC_GOTRUE_URL).origin
: ''
-const SUPABASE_PROJECTS_URL = 'https://*.supabase.co'
+const SUPABASE_PROJECTS_URL = 'https://*.supabase.co https://*.storage.supabase.co'
const SUPABASE_PROJECTS_URL_WS = 'wss://*.supabase.co'
// construct the URL for the Websocket Local URLs
@@ -37,7 +37,7 @@ const NIMBUS_STAGING_PROJECTS_URL_WS = 'wss://*.nmb-proj.com'
const NIMBUS_PROD_PROJECTS_URL = process.env.NIMBUS_PROD_PROJECTS_URL || ''
const NIMBUS_PROD_PROJECTS_URL_WS = process.env.NIMBUS_PROD_PROJECTS_URL_WS || ''
-const SUPABASE_STAGING_PROJECTS_URL = 'https://*.supabase.red'
+const SUPABASE_STAGING_PROJECTS_URL = 'https://*.supabase.red https://*.storage.supabase.red'
const SUPABASE_STAGING_PROJECTS_URL_WS = 'wss://*.supabase.red'
const SUPABASE_COM_URL = 'https://supabase.com'
const CLOUDFLARE_CDN_URL = 'https://cdnjs.cloudflare.com'
diff --git a/apps/studio/data/config/project-endpoint-query.ts b/apps/studio/data/config/project-endpoint-query.ts
index 3407df5995a..4f4445e5213 100644
--- a/apps/studio/data/config/project-endpoint-query.ts
+++ b/apps/studio/data/config/project-endpoint-query.ts
@@ -1,4 +1,5 @@
import { IS_PLATFORM } from 'common'
+
import { ProjectSettingsVariables, useProjectSettingsV2Query } from './project-settings-v2-query'
export const useProjectEndpointQuery = ({ projectRef }: ProjectSettingsVariables) => {
@@ -9,8 +10,11 @@ export const useProjectEndpointQuery = ({ projectRef }: ProjectSettingsVariables
const protocol = data?.app_config?.protocol ?? 'https'
const endpoint = data?.app_config?.endpoint
const clientEndpoint = `${IS_PLATFORM ? 'https' : protocol}://${endpoint}`
+ const storageEndpoint = data?.app_config?.storage_endpoint
+ ? `${IS_PLATFORM ? 'https' : protocol}://${data?.app_config?.storage_endpoint}`
+ : undefined
- return { endpoint: clientEndpoint }
+ return { endpoint: clientEndpoint, storageEndpoint }
},
}
)
diff --git a/apps/studio/state/storage-explorer.tsx b/apps/studio/state/storage-explorer.tsx
index a5508a2a6a0..85e4eb938e7 100644
--- a/apps/studio/state/storage-explorer.tsx
+++ b/apps/studio/state/storage-explorer.tsx
@@ -1,17 +1,17 @@
import { BlobReader, BlobWriter, ZipWriter } from '@zip.js/zip.js'
+import { IS_PLATFORM, LOCAL_STORAGE_KEYS } from 'common'
import { capitalize, chunk, compact, find, findIndex, has, isObject, uniq, uniqBy } from 'lodash'
import { createContext, PropsWithChildren, useContext, useEffect, useState } from 'react'
import { useLatest } from 'react-use'
import { toast } from 'sonner'
import * as tus from 'tus-js-client'
+import { Button, SONNER_DEFAULT_DURATION, SonnerProgress } from 'ui'
import { proxy, useSnapshot } from 'valtio'
-import { ResponseError } from '@/types'
-import { LOCAL_STORAGE_KEYS } from 'common'
import {
inverseValidObjectKeyRegex,
validObjectKeyRegex,
-} from 'components/interfaces/Storage/CreateBucketModal.utils'
+} from '@/components/interfaces/Storage/CreateBucketModal.utils'
import {
STORAGE_BUCKET_SORT,
STORAGE_ROW_STATUS,
@@ -19,38 +19,38 @@ import {
STORAGE_SORT_BY,
STORAGE_SORT_BY_ORDER,
STORAGE_VIEWS,
-} from 'components/interfaces/Storage/Storage.constants'
+} from '@/components/interfaces/Storage/Storage.constants'
import {
StorageColumn,
StorageItem,
StorageItemMetadata,
StorageItemWithColumn,
-} from 'components/interfaces/Storage/Storage.types'
+} from '@/components/interfaces/Storage/Storage.types'
import {
calculateTotalRemainingTime,
EMPTY_FOLDER_PLACEHOLDER_FILE_NAME,
formatFolderItems,
formatTime,
getFilesDataTransferItems,
-} from 'components/interfaces/Storage/StorageExplorer/StorageExplorer.utils'
-import { convertFromBytes } from 'components/interfaces/Storage/StorageSettings/StorageSettings.utils'
-import { InlineLink } from 'components/ui/InlineLink'
-import { getOrRefreshTemporaryApiKey } from 'data/api-keys/temp-api-keys-utils'
-import { configKeys } from 'data/config/keys'
-import { useProjectEndpointQuery } from 'data/config/project-endpoint-query'
-import { ProjectStorageConfigResponse } from 'data/config/project-storage-config-query'
-import { getQueryClient } from 'data/query-client'
-import { deleteBucketObject } from 'data/storage/bucket-object-delete-mutation'
-import { listBucketObjects, StorageObject } from 'data/storage/bucket-objects-list-mutation'
-import { deleteBucketPrefix } from 'data/storage/bucket-prefix-delete-mutation'
-import { Bucket } from 'data/storage/buckets-query'
-import { moveStorageObject } from 'data/storage/object-move-mutation'
-import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
-import { IS_PLATFORM, PROJECT_STATUS } from 'lib/constants'
-import { tryParseJson } from 'lib/helpers'
-import { lookupMime } from 'lib/mime'
-import { createProjectSupabaseClient } from 'lib/project-supabase-client'
-import { Button, SONNER_DEFAULT_DURATION, SonnerProgress } from 'ui'
+} from '@/components/interfaces/Storage/StorageExplorer/StorageExplorer.utils'
+import { convertFromBytes } from '@/components/interfaces/Storage/StorageSettings/StorageSettings.utils'
+import { InlineLink } from '@/components/ui/InlineLink'
+import { getOrRefreshTemporaryApiKey } from '@/data/api-keys/temp-api-keys-utils'
+import { configKeys } from '@/data/config/keys'
+import { useProjectEndpointQuery } from '@/data/config/project-endpoint-query'
+import type { ProjectStorageConfigResponse } from '@/data/config/project-storage-config-query'
+import { getQueryClient } from '@/data/query-client'
+import { deleteBucketObject } from '@/data/storage/bucket-object-delete-mutation'
+import { listBucketObjects, StorageObject } from '@/data/storage/bucket-objects-list-mutation'
+import { deleteBucketPrefix } from '@/data/storage/bucket-prefix-delete-mutation'
+import type { Bucket } from '@/data/storage/buckets-query'
+import { moveStorageObject } from '@/data/storage/object-move-mutation'
+import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
+import { PROJECT_STATUS } from '@/lib/constants'
+import { tryParseJson } from '@/lib/helpers'
+import { lookupMime } from '@/lib/mime'
+import { createProjectSupabaseClient } from '@/lib/project-supabase-client'
+import { ResponseError } from '@/types'
type UploadProgress = {
percentage: number
@@ -1159,17 +1159,17 @@ function createStorageExplorerState({
let chunkSize: number
if (fileSizeInMB < 30) {
- chunkSize = 6 * 1024 * 1024
+ chunkSize = 6 * 1024 * 1024 // 6MB
} else if (fileSizeInMB < 100) {
- chunkSize = Math.floor(file.size / 8)
+ chunkSize = Math.floor(file.size / 8) // maximum 8 chunks, 12,5MB each
} else if (fileSizeInMB < 500) {
- chunkSize = Math.floor(file.size / 10)
+ chunkSize = Math.floor(file.size / 10) // maximum 10 chunks, 50MB each
} else if (fileSizeInMB < 1024) {
- chunkSize = Math.floor(file.size / 20)
+ chunkSize = Math.floor(file.size / 20) // maximum 20 chunks, 50MB each
} else if (fileSizeInMB < 10 * 1024) {
- chunkSize = Math.floor(file.size / 30)
+ chunkSize = Math.floor(file.size / 30) // maximum 30 chunks, 333MB each
} else {
- chunkSize = Math.floor(file.size / 50)
+ chunkSize = Math.floor(file.size / 50) // maximum 50 chunks
}
// Max chunk size is 500MB
@@ -1906,7 +1906,7 @@ export const StorageExplorerStateContextProvider = ({ children }: PropsWithChild
const storeAlreadyLoaded = state.projectRef === project?.ref
if (!isPaused && hasDataReady && !storeAlreadyLoaded && isSuccessSettings) {
- const clientEndpoint = endpointData.endpoint
+ const clientEndpoint = endpointData.storageEndpoint ?? endpointData.endpoint
const resumableUploadUrl = `${clientEndpoint}/storage/v1/upload/resumable`
setState(
createStorageExplorerState({
@@ -1924,6 +1924,7 @@ export const StorageExplorerStateContextProvider = ({ children }: PropsWithChild
stateRef,
isPaused,
endpointData?.endpoint,
+ endpointData?.storageEndpoint,
isSuccessSettings,
])