Skip to content

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

Chore/fix storage upload folder logic (#27744)

Joshen Lim59c8b9449fb0
diff --git a/apps/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerColumn.tsx b/apps/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerColumn.tsx
index bde5fd2b72a..e4b559a1c53 100644
--- a/apps/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerColumn.tsx
+++ b/apps/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerColumn.tsx
@@ -2,12 +2,13 @@ import { Transition } from '@headlessui/react'
import { get, noop, sum } from 'lodash'
import { useEffect, useRef, useState } from 'react'
import { useContextMenu } from 'react-contexify'
-import { Checkbox, IconUpload } from 'ui'
+import { Checkbox } from 'ui'
import InfiniteList from 'components/ui/InfiniteList'
import ShimmeringLoader from 'components/ui/ShimmeringLoader'
import { BASE_PATH } from 'lib/constants'
import { formatBytes } from 'lib/helpers'
+import { Upload } from 'lucide-react'
import { useStorageExplorerStateSnapshot } from 'state/storage-explorer'
import {
CONTEXT_MENU_KEYS,
@@ -41,7 +42,7 @@ const DragOverOverlay = ({ isOpen, onDragLeave, onDrop, folderIsEmpty }: any) =>
className="w-3/4 h-32 border-2 border-dashed border-muted rounded-md flex flex-col items-center justify-center p-6 pointer-events-none"
style={{ backgroundColor: 'rgba(0,0,0,0.4)' }}
>
- <IconUpload className="text-white pointer-events-none" size={20} strokeWidth={2} />
+ <Upload className="text-white pointer-events-none" size={20} strokeWidth={2} />
<p className="text-center text-sm text-white mt-2 pointer-events-none">
Drop your files to upload to this folder
</p>
diff --git a/apps/studio/localStores/storageExplorer/StorageExplorerStore.tsx b/apps/studio/localStores/storageExplorer/StorageExplorerStore.tsx
index 3ec760e3357..db987c90349 100644
--- a/apps/studio/localStores/storageExplorer/StorageExplorerStore.tsx
+++ b/apps/studio/localStores/storageExplorer/StorageExplorerStore.tsx
@@ -530,24 +530,26 @@ class StorageExplorerStore {
const topLevelFolders: string[] = (this.columns?.[derivedColumnIndex]?.items ?? [])
.filter((item) => !item.id)
.map((item) => item.name)
- const formattedFilesToUpload = filesWithinUploadLimit.map((file) => {
- // If the files are from clicking "Upload button", just take them as they are since users cannot
- // upload folders from clicking that button, only via drag drop
- if (!file.path) return file
-
- const path = file.path.split('/')
- const topLevelFolder = path.length > 1 ? path[0] : null
- if (topLevelFolders.includes(topLevelFolder as string)) {
- const newTopLevelFolder = this.sanitizeNameForDuplicateInColumn(
- topLevelFolder as string,
- autofix,
- columnIndex
- )
- path[0] = newTopLevelFolder as string
- file.path = path.join('/')
- }
- return file
- })
+ const formattedFilesToUpload = filesWithinUploadLimit
+ .filter((file) => file.name !== '.DS_Store')
+ .map((file) => {
+ // If the files are from clicking "Upload button", just take them as they are since users cannot
+ // upload folders from clicking that button, only via drag drop
+ if (!file.path) return file
+
+ const path = file.path.split('/')
+ const topLevelFolder = path.length > 1 ? path[0] : null
+ if (topLevelFolders.includes(topLevelFolder as string)) {
+ const newTopLevelFolder = this.sanitizeNameForDuplicateInColumn(
+ topLevelFolder as string,
+ autofix,
+ columnIndex
+ )
+ path[0] = newTopLevelFolder as string
+ file.path = path.join('/')
+ }
+ return file
+ })
this.uploadProgress = 0
const uploadedTopLevelFolders: string[] = []
@@ -585,8 +587,13 @@ class StorageExplorerStore {
* Storage maintains a list of allowed characters, which excludes
* characters such as the narrow no-break space used in Mac screenshots.
* To preempt errors, replace all non-word characters with underscores.
+ * [Joshen] Except backslashes as this will indicate a folder path, and paranthesis
+ * since our UI appends them to make duplicate names unique
*/
- const formattedFileName = (unsanitizedFormattedFileName ?? 'unknown').replace(/[^\w.-]/g, '_')
+ const formattedFileName = (unsanitizedFormattedFileName ?? 'unknown').replace(
+ /[^\w.-\/()]/g,
+ '_'
+ )
const formattedPathToFile =
pathToFile.length > 0 ? `${pathToFile}/${formattedFileName}` : (formattedFileName as string)