From 40322b20b60decd2175da93fc1465026fc8fed71 Mon Sep 17 00:00:00 2001 From: Alaister Young Date: Tue, 17 Sep 2024 08:40:40 +0100 Subject: [PATCH] fix: error on invalid mime types (#29337) * fix: error on invalid mime types * allow server to check mime type instead of client * swap ?? for || * fix upload icon import --- .../StorageExplorer/FileExplorerHeader.tsx | 28 +++++++-------- .../storageExplorer/StorageExplorerStore.tsx | 35 ++++++++++++++++--- 2 files changed, 45 insertions(+), 18 deletions(-) diff --git a/apps/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerHeader.tsx b/apps/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerHeader.tsx index dd7c707a191..d96a99bf24a 100644 --- a/apps/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerHeader.tsx +++ b/apps/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerHeader.tsx @@ -7,6 +7,20 @@ import { useIsAPIDocsSidePanelEnabled } from 'components/interfaces/App/FeatureP import APIDocsButton from 'components/ui/APIDocsButton' import { useCheckPermissions } from 'hooks/misc/useCheckPermissions' import { useStorageStore } from 'localStores/storageExplorer/StorageExplorerStore' +import { + Check, + ChevronLeft, + ChevronRight, + Columns, + Edit2, + FolderPlus, + List, + Loader, + RefreshCw, + Search, + Upload, + X, +} from 'lucide-react' import { useStorageExplorerStateSnapshot } from 'state/storage-explorer' import { Button, @@ -19,22 +33,8 @@ import { DropdownMenuSubTrigger, DropdownMenuTrigger, Input, - Upload, } from 'ui' import { STORAGE_SORT_BY, STORAGE_SORT_BY_ORDER, STORAGE_VIEWS } from '../Storage.constants' -import { - Loader, - Edit2, - ChevronRight, - ChevronLeft, - RefreshCw, - List, - Columns, - Check, - FolderPlus, - Search, - X, -} from 'lucide-react' const VIEW_OPTIONS = [ { key: STORAGE_VIEWS.COLUMNS, name: 'As columns' }, diff --git a/apps/studio/localStores/storageExplorer/StorageExplorerStore.tsx b/apps/studio/localStores/storageExplorer/StorageExplorerStore.tsx index 336f18ba7c9..a6858e9a5fb 100644 --- a/apps/studio/localStores/storageExplorer/StorageExplorerStore.tsx +++ b/apps/studio/localStores/storageExplorer/StorageExplorerStore.tsx @@ -1,6 +1,17 @@ import { SupabaseClient, createClient } from '@supabase/supabase-js' import { BlobReader, BlobWriter, ZipWriter } from '@zip.js/zip.js' -import { chunk, compact, find, findIndex, has, isEqual, isObject, uniq, uniqBy } from 'lodash' +import { + capitalize, + chunk, + compact, + find, + findIndex, + has, + isEqual, + isObject, + uniq, + uniqBy, +} from 'lodash' import { makeAutoObservable } from 'mobx' import { toast } from 'sonner' import * as tus from 'tus-js-client' @@ -722,13 +733,29 @@ class StorageExplorerStore { chunkSize, onShouldRetry(error) { const status = error.originalResponse ? error.originalResponse.getStatus() : 0 - const doNotRetryStatuses = [400, 403, 404, 409, 429] + const doNotRetryStatuses = [400, 403, 404, 409, 415, 429] return !doNotRetryStatuses.includes(status) }, - onError(error) { + onError: (error) => { numberOfFilesUploadedFail += 1 - toast.error(`Failed to upload ${file.name}: ${error.message}`) + if ( + error instanceof tus.DetailedError && + error.originalResponse?.getStatus() === 415 + ) { + // Unsupported mime type + toast.error( + capitalize( + error.originalResponse.getBody() || + `Failed to upload ${file.name}: ${metadata.mimetype} is not allowed` + ), + { + description: `Allowed MIME types: ${this.selectedBucket.allowed_mime_types?.join(', ')}`, + } + ) + } else { + toast.error(`Failed to upload ${file.name}: ${error.message}`) + } reject(error) }, onProgress: (bytesSent, bytesTotal) => {