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}

) } else { diff --git a/ui/yarn.lock b/ui/yarn.lock index 2909405d..df7f104b 100644 --- a/ui/yarn.lock +++ b/ui/yarn.lock @@ -2921,7 +2921,7 @@ at-least-node@^1.0.0: resolved "https://registry.yarnpkg.com/at-least-node/-/at-least-node-1.0.0.tgz#602cd4b46e844ad4effc92a8011a3c46e0238dc2" integrity sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg== -attr-accept@^2.2.4: +attr-accept@^2.2.2: version "2.2.5" resolved "https://registry.yarnpkg.com/attr-accept/-/attr-accept-2.2.5.tgz#d7061d958e6d4f97bf8665c68b75851a0713ab5e" integrity sha512-0bDNnY/u6pPwHDMoF0FieU354oBi0a8rD9FcsLwzcGWbc8KS8KPIi7y+s13OlVY+gMWc/9xEMUgNE6Qm8ZllYQ== @@ -4838,12 +4838,12 @@ file-loader@^6.2.0: loader-utils "^2.0.0" schema-utils "^3.0.0" -file-selector@^2.1.0: - version "2.1.0" - resolved "https://registry.yarnpkg.com/file-selector/-/file-selector-2.1.0.tgz#beb164ca5ce48af8a48d3e632c94750bc573581a" - integrity sha512-ZuXAqGePcSPz4JuerOY06Dzzq0hrmQ6VGoXVzGyFI1npeOfBgqGIKKpznfYWRkSLJlXutkqVC5WvGZtkFVhu9Q== +file-selector@^0.4.0: + version "0.4.0" + resolved "https://registry.yarnpkg.com/file-selector/-/file-selector-0.4.0.tgz#59ec4f27aa5baf0841e9c6385c8386bef4d18b17" + integrity sha512-iACCiXeMYOvZqlF1kTiYINzgepRBymz1wwjiuup9u9nayhb6g4fSwiyJ/6adli+EPwrWtpgQAh2PoS7HukEGEg== dependencies: - tslib "^2.7.0" + tslib "^2.0.3" filelist@^1.0.4: version "1.0.4" @@ -8233,20 +8233,13 @@ react-dom@^18.3.1: loose-envify "^1.1.0" scheduler "^0.23.2" -react-dropzone-uploader@^2.11.0: - version "2.11.0" - resolved "https://registry.yarnpkg.com/react-dropzone-uploader/-/react-dropzone-uploader-2.11.0.tgz#6579e83f4f98c8248a3f3b5825c436ca3d6441cf" - integrity sha512-1DpdPMGKP7vYL5SeCh13HCl+Xrz0F6jGrDPU5Tj2ojEIXGMCtfflrZhyXdr7u40IkQ+hYjAUEEtJW24SiY8WRA== - dependencies: - "@babel/runtime" "^7.1.2" - -react-dropzone@^14.3.5: - version "14.3.5" - resolved "https://registry.yarnpkg.com/react-dropzone/-/react-dropzone-14.3.5.tgz#1a8bd312c8a353ec78ef402842ccb3589c225add" - integrity sha512-9nDUaEEpqZLOz5v5SUcFA0CjM4vq8YbqO0WRls+EYT7+DvxUdzDPKNCPLqGfj3YL9MsniCLCD4RFA6M95V6KMQ== +react-dropzone@^11.3.2: + version "11.7.1" + resolved "https://registry.yarnpkg.com/react-dropzone/-/react-dropzone-11.7.1.tgz#3851bb75b26af0bf1b17ce1449fd980e643b9356" + integrity sha512-zxCMwhfPy1olUEbw3FLNPLhAm/HnaYH5aELIEglRbqabizKAdHs0h+WuyOpmA+v1JXn0++fpQDdNfUagWt5hJQ== dependencies: - attr-accept "^2.2.4" - file-selector "^2.1.0" + attr-accept "^2.2.2" + file-selector "^0.4.0" prop-types "^15.8.1" react-error-overlay@^6.0.11: @@ -9615,7 +9608,7 @@ tslib@^1.8.1: resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00" integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg== -tslib@^2.0.3, tslib@^2.7.0, tslib@^2.8.0: +tslib@^2.0.3, tslib@^2.8.0: version "2.8.1" resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.8.1.tgz#612efe4ed235d567e8aba5f2a5fab70280ade83f" integrity sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==