Skip to content

Commit

Permalink
- some fixes with upload control version
Browse files Browse the repository at this point in the history
- 404 instead of 500 on blob not found
  • Loading branch information
ddvk committed Nov 17, 2024
1 parent 4b569fc commit 70f801d
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 35 deletions.
5 changes: 5 additions & 0 deletions internal/app/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions internal/storage/filetypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ const (
EpubFileExt = ".epub"
//PdfFileExt pdf
PdfFileExt = ".pdf"
//RmDoc
RmDocFileExt = ".rmdoc"
)
13 changes: 10 additions & 3 deletions internal/storage/fs/blobstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion internal/ui/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
3 changes: 1 addition & 2 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 4 additions & 9 deletions ui/src/pages/Documents/Upload.js
Original file line number Diff line number Diff line change
@@ -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) => {
Expand All @@ -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();
}
}

Expand All @@ -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 (
<div {...getRootProps({ className })}>
<input {...getInputProps()} />
<p>{wasError ? lasterror : hint}</p>
<p>{ hint}</p>
</div>
)
} else {
Expand Down
33 changes: 13 additions & 20 deletions ui/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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==
Expand Down

0 comments on commit 70f801d

Please sign in to comment.