From 70f801da65a12e6bcb0fe2180bd0116cc355c82c Mon Sep 17 00:00:00 2001 From: ddvk <36803246+ddvk@users.noreply.github.com> Date: Sun, 17 Nov 2024 19:58:18 +0100 Subject: [PATCH] - some fixes with upload control version - 404 instead of 500 on blob not found --- internal/app/handlers.go | 5 +++++ internal/storage/filetypes.go | 2 ++ internal/storage/fs/blobstore.go | 13 ++++++++++--- internal/ui/handlers.go | 5 ++++- ui/package.json | 3 +-- ui/src/pages/Documents/Upload.js | 13 ++++--------- ui/yarn.lock | 33 +++++++++++++------------------- 7 files changed, 39 insertions(+), 35 deletions(-) diff --git a/internal/app/handlers.go b/internal/app/handlers.go index 61c9cac4..48619617 100644 --- a/internal/app/handlers.go +++ b/internal/app/handlers.go @@ -873,6 +873,11 @@ func (app *App) blobStorageRead(c *gin.Context) { blobID := common.ParamS(fileKey, c) reader, _, size, crc32c, err := app.blobStorer.LoadBlob(uid, blobID) + if err == fs.ErrorNotFound { + log.Warn(err) + c.AbortWithStatus(http.StatusNotFound) + return + } if err != nil { log.Error(err) c.AbortWithStatus(http.StatusInternalServerError) diff --git a/internal/storage/filetypes.go b/internal/storage/filetypes.go index ef4ba84c..e1bf49e7 100644 --- a/internal/storage/filetypes.go +++ b/internal/storage/filetypes.go @@ -12,4 +12,6 @@ const ( EpubFileExt = ".epub" //PdfFileExt pdf PdfFileExt = ".pdf" + //RmDoc + RmDocFileExt = ".rmdoc" ) diff --git a/internal/storage/fs/blobstore.go b/internal/storage/fs/blobstore.go index b061efef..17abce6a 100644 --- a/internal/storage/fs/blobstore.go +++ b/internal/storage/fs/blobstore.go @@ -277,12 +277,15 @@ func updateTree(tree *models.HashTree, storage *LocalBlobStorage, treeMutation f func (fs *FileSystemStorage) CreateBlobDocument(uid, filename, parent string, stream io.Reader) (doc *storage.Document, err error) { ext := path.Ext(filename) switch ext { - case storage.PdfFileExt: - fallthrough - case storage.EpubFileExt: + case storage.EpubFileExt, storage.PdfFileExt, storage.RmDocFileExt: default: return nil, errors.New("unsupported extension: " + ext) } + + if ext == storage.RmDocFileExt{ + return nil, errors.New("TODO: not implemented yet") + } + //TODO: zips and rm blobPath := fs.getUserBlobPath(uid) docid := uuid.New().String() @@ -476,6 +479,10 @@ func (fs *FileSystemStorage) LoadBlob(uid, blobid string) (reader io.ReadCloser, } osFile, err := os.Open(blobPath) + if err != nil { + log.Errorf("cannot open blob %v", err) + return + } //TODO: cache the crc32 crc32, err = common.CRC32FromReader(osFile) if err != nil { diff --git a/internal/ui/handlers.go b/internal/ui/handlers.go index 03ac0213..5d752386 100644 --- a/internal/ui/handlers.go +++ b/internal/ui/handlers.go @@ -350,8 +350,11 @@ func (app *ReactAppWrapper) createDocument(c *gin.Context) { } parentID := "" if parent, ok := form.Value["parent"]; ok { - parentID = parent[0] + if parent[0] != "root" { + parentID = parent[0] + } } + log.Info("Parent: " + parentID) docs := []*storage.Document{} diff --git a/ui/package.json b/ui/package.json index 61ccc9e0..05fcc8fe 100644 --- a/ui/package.json +++ b/ui/package.json @@ -13,8 +13,7 @@ "react-arborist": "^3.4.0", "react-bootstrap": "^2.10.0", "react-dom": "^18.3.1", - "react-dropzone": "^14.3.5", - "react-dropzone-uploader": "^2.11.0", + "react-dropzone": "^11.3.2", "react-icons": "^4.2.0", "react-pdf": "^9.1.1", "react-router-dom": "^5.3.0", diff --git a/ui/src/pages/Documents/Upload.js b/ui/src/pages/Documents/Upload.js index 6e419d85..e768f8c8 100644 --- a/ui/src/pages/Documents/Upload.js +++ b/ui/src/pages/Documents/Upload.js @@ -1,14 +1,13 @@ import { useMemo, useState } from 'react'; import { useDropzone } from 'react-dropzone'; import Spinner from 'react-bootstrap/Spinner'; - +import { toast } from "react-toastify"; import apiservice from "../../services/api.service"; import styles from "./Documents.module.scss"; export default function StyledDropzone(props) { const [uploading, setUploading] = useState(false); - const [lasterror, setLastError] = useState(); const uploadFolder = props.uploadFolder; var onDrop = async (acceptedFiles) => { @@ -17,14 +16,12 @@ export default function StyledDropzone(props) { // TODO: add loading and error handling await apiservice.upload(uploadFolder, acceptedFiles) // await delay(100) - setLastError(null) + props.filesUploaded(); } catch (e) { - setLastError(e) - console.error(e) + toast.error('upload error' + e.toString()) } finally{ setUploading(false); - props.filesUploaded(); } } @@ -44,13 +41,11 @@ export default function StyledDropzone(props) { }, [isDragActive, isDragReject, isDragAccept]) const hint = "Drag 'n' drop some files here, or click to select files to upload" - const wasError = lasterror !== undefined && lasterror !== null && lasterror !== "" - if (!uploading) { return (
{wasError ? lasterror : hint}
+{ hint}