diff --git a/pkg/dashboard/frontend/src/components/storage/FileBrowser.tsx b/pkg/dashboard/frontend/src/components/storage/FileBrowser.tsx index 372765d2..3ce5ab0f 100644 --- a/pkg/dashboard/frontend/src/components/storage/FileBrowser.tsx +++ b/pkg/dashboard/frontend/src/components/storage/FileBrowser.tsx @@ -29,6 +29,11 @@ setChonkyDefaults({ iconComponent: ChonkyIconFA, }) +// covers most image types, could detect from the file itself in the future +const isImage = (file: FileData) => { + return /\.(jpe?g|png|gif|bmp|webp|tiff?|heic|heif|ico|svg)$/i.test(file.name) +} + function generateTree(data: { key: string }[]): FileData[] { const tree: FileData[] = [] @@ -258,7 +263,7 @@ const FileBrowser: FC = ({ bucket }) => { folderChain={folderChain} onFileAction={handleFileAction} thumbnailGenerator={(file) => - !file.isDir + !file.isDir && isImage(file) ? `${STORAGE_API}?action=read-file&bucket=${bucket}&fileKey=${encodeURI( file.id, )}` diff --git a/pkg/dashboard/handlers.go b/pkg/dashboard/handlers.go index 087a1045..941c088d 100644 --- a/pkg/dashboard/handlers.go +++ b/pkg/dashboard/handlers.go @@ -59,16 +59,18 @@ func (d *Dashboard) handleStorage() func(http.ResponseWriter, *http.Request) { bucketName := r.URL.Query().Get("bucket") action := r.URL.Query().Get("action") + // Set the content type to JSON for all actions except read-file, to prevent it being set to text/plain + if action != "read-file" { + w.Header().Set("Content-Type", "application/json") + } + if bucketName == "" && action != "list-buckets" { w.WriteHeader(http.StatusBadRequest) - w.Header().Set("Content-Type", "application/json") handleResponseWriter(w, []byte(`{"error": "Bucket is required"}`)) return } - w.Header().Set("Content-Type", "application/json") - switch action { case "read-file": fileKey := r.URL.Query().Get("fileKey")