Skip to content

Commit 70f801d

Browse files
committed
- some fixes with upload control version
- 404 instead of 500 on blob not found
1 parent 4b569fc commit 70f801d

File tree

7 files changed

+39
-35
lines changed

7 files changed

+39
-35
lines changed

internal/app/handlers.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,11 @@ func (app *App) blobStorageRead(c *gin.Context) {
873873
blobID := common.ParamS(fileKey, c)
874874

875875
reader, _, size, crc32c, err := app.blobStorer.LoadBlob(uid, blobID)
876+
if err == fs.ErrorNotFound {
877+
log.Warn(err)
878+
c.AbortWithStatus(http.StatusNotFound)
879+
return
880+
}
876881
if err != nil {
877882
log.Error(err)
878883
c.AbortWithStatus(http.StatusInternalServerError)

internal/storage/filetypes.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ const (
1212
EpubFileExt = ".epub"
1313
//PdfFileExt pdf
1414
PdfFileExt = ".pdf"
15+
//RmDoc
16+
RmDocFileExt = ".rmdoc"
1517
)

internal/storage/fs/blobstore.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,15 @@ func updateTree(tree *models.HashTree, storage *LocalBlobStorage, treeMutation f
277277
func (fs *FileSystemStorage) CreateBlobDocument(uid, filename, parent string, stream io.Reader) (doc *storage.Document, err error) {
278278
ext := path.Ext(filename)
279279
switch ext {
280-
case storage.PdfFileExt:
281-
fallthrough
282-
case storage.EpubFileExt:
280+
case storage.EpubFileExt, storage.PdfFileExt, storage.RmDocFileExt:
283281
default:
284282
return nil, errors.New("unsupported extension: " + ext)
285283
}
284+
285+
if ext == storage.RmDocFileExt{
286+
return nil, errors.New("TODO: not implemented yet")
287+
}
288+
286289
//TODO: zips and rm
287290
blobPath := fs.getUserBlobPath(uid)
288291
docid := uuid.New().String()
@@ -476,6 +479,10 @@ func (fs *FileSystemStorage) LoadBlob(uid, blobid string) (reader io.ReadCloser,
476479
}
477480

478481
osFile, err := os.Open(blobPath)
482+
if err != nil {
483+
log.Errorf("cannot open blob %v", err)
484+
return
485+
}
479486
//TODO: cache the crc32
480487
crc32, err = common.CRC32FromReader(osFile)
481488
if err != nil {

internal/ui/handlers.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,11 @@ func (app *ReactAppWrapper) createDocument(c *gin.Context) {
350350
}
351351
parentID := ""
352352
if parent, ok := form.Value["parent"]; ok {
353-
parentID = parent[0]
353+
if parent[0] != "root" {
354+
parentID = parent[0]
355+
}
354356
}
357+
355358
log.Info("Parent: " + parentID)
356359

357360
docs := []*storage.Document{}

ui/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
"react-arborist": "^3.4.0",
1414
"react-bootstrap": "^2.10.0",
1515
"react-dom": "^18.3.1",
16-
"react-dropzone": "^14.3.5",
17-
"react-dropzone-uploader": "^2.11.0",
16+
"react-dropzone": "^11.3.2",
1817
"react-icons": "^4.2.0",
1918
"react-pdf": "^9.1.1",
2019
"react-router-dom": "^5.3.0",

ui/src/pages/Documents/Upload.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import { useMemo, useState } from 'react';
22
import { useDropzone } from 'react-dropzone';
33
import Spinner from 'react-bootstrap/Spinner';
4-
4+
import { toast } from "react-toastify";
55
import apiservice from "../../services/api.service";
66

77
import styles from "./Documents.module.scss";
88

99
export default function StyledDropzone(props) {
1010
const [uploading, setUploading] = useState(false);
11-
const [lasterror, setLastError] = useState();
1211
const uploadFolder = props.uploadFolder;
1312

1413
var onDrop = async (acceptedFiles) => {
@@ -17,14 +16,12 @@ export default function StyledDropzone(props) {
1716
// TODO: add loading and error handling
1817
await apiservice.upload(uploadFolder, acceptedFiles)
1918
// await delay(100)
20-
setLastError(null)
19+
props.filesUploaded();
2120
} catch (e) {
22-
setLastError(e)
23-
console.error(e)
21+
toast.error('upload error' + e.toString())
2422
}
2523
finally{
2624
setUploading(false);
27-
props.filesUploaded();
2825
}
2926
}
3027

@@ -44,13 +41,11 @@ export default function StyledDropzone(props) {
4441
}, [isDragActive, isDragReject, isDragAccept])
4542

4643
const hint = "Drag 'n' drop some files here, or click to select files to upload"
47-
const wasError = lasterror !== undefined && lasterror !== null && lasterror !== ""
48-
4944
if (!uploading) {
5045
return (
5146
<div {...getRootProps({ className })}>
5247
<input {...getInputProps()} />
53-
<p>{wasError ? lasterror : hint}</p>
48+
<p>{ hint}</p>
5449
</div>
5550
)
5651
} else {

ui/yarn.lock

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2921,7 +2921,7 @@ at-least-node@^1.0.0:
29212921
resolved "https://registry.yarnpkg.com/at-least-node/-/at-least-node-1.0.0.tgz#602cd4b46e844ad4effc92a8011a3c46e0238dc2"
29222922
integrity sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==
29232923

2924-
attr-accept@^2.2.4:
2924+
attr-accept@^2.2.2:
29252925
version "2.2.5"
29262926
resolved "https://registry.yarnpkg.com/attr-accept/-/attr-accept-2.2.5.tgz#d7061d958e6d4f97bf8665c68b75851a0713ab5e"
29272927
integrity sha512-0bDNnY/u6pPwHDMoF0FieU354oBi0a8rD9FcsLwzcGWbc8KS8KPIi7y+s13OlVY+gMWc/9xEMUgNE6Qm8ZllYQ==
@@ -4838,12 +4838,12 @@ file-loader@^6.2.0:
48384838
loader-utils "^2.0.0"
48394839
schema-utils "^3.0.0"
48404840

4841-
file-selector@^2.1.0:
4842-
version "2.1.0"
4843-
resolved "https://registry.yarnpkg.com/file-selector/-/file-selector-2.1.0.tgz#beb164ca5ce48af8a48d3e632c94750bc573581a"
4844-
integrity sha512-ZuXAqGePcSPz4JuerOY06Dzzq0hrmQ6VGoXVzGyFI1npeOfBgqGIKKpznfYWRkSLJlXutkqVC5WvGZtkFVhu9Q==
4841+
file-selector@^0.4.0:
4842+
version "0.4.0"
4843+
resolved "https://registry.yarnpkg.com/file-selector/-/file-selector-0.4.0.tgz#59ec4f27aa5baf0841e9c6385c8386bef4d18b17"
4844+
integrity sha512-iACCiXeMYOvZqlF1kTiYINzgepRBymz1wwjiuup9u9nayhb6g4fSwiyJ/6adli+EPwrWtpgQAh2PoS7HukEGEg==
48454845
dependencies:
4846-
tslib "^2.7.0"
4846+
tslib "^2.0.3"
48474847

48484848
filelist@^1.0.4:
48494849
version "1.0.4"
@@ -8233,20 +8233,13 @@ react-dom@^18.3.1:
82338233
loose-envify "^1.1.0"
82348234
scheduler "^0.23.2"
82358235

8236-
react-dropzone-uploader@^2.11.0:
8237-
version "2.11.0"
8238-
resolved "https://registry.yarnpkg.com/react-dropzone-uploader/-/react-dropzone-uploader-2.11.0.tgz#6579e83f4f98c8248a3f3b5825c436ca3d6441cf"
8239-
integrity sha512-1DpdPMGKP7vYL5SeCh13HCl+Xrz0F6jGrDPU5Tj2ojEIXGMCtfflrZhyXdr7u40IkQ+hYjAUEEtJW24SiY8WRA==
8240-
dependencies:
8241-
"@babel/runtime" "^7.1.2"
8242-
8243-
react-dropzone@^14.3.5:
8244-
version "14.3.5"
8245-
resolved "https://registry.yarnpkg.com/react-dropzone/-/react-dropzone-14.3.5.tgz#1a8bd312c8a353ec78ef402842ccb3589c225add"
8246-
integrity sha512-9nDUaEEpqZLOz5v5SUcFA0CjM4vq8YbqO0WRls+EYT7+DvxUdzDPKNCPLqGfj3YL9MsniCLCD4RFA6M95V6KMQ==
8236+
react-dropzone@^11.3.2:
8237+
version "11.7.1"
8238+
resolved "https://registry.yarnpkg.com/react-dropzone/-/react-dropzone-11.7.1.tgz#3851bb75b26af0bf1b17ce1449fd980e643b9356"
8239+
integrity sha512-zxCMwhfPy1olUEbw3FLNPLhAm/HnaYH5aELIEglRbqabizKAdHs0h+WuyOpmA+v1JXn0++fpQDdNfUagWt5hJQ==
82478240
dependencies:
8248-
attr-accept "^2.2.4"
8249-
file-selector "^2.1.0"
8241+
attr-accept "^2.2.2"
8242+
file-selector "^0.4.0"
82508243
prop-types "^15.8.1"
82518244

82528245
react-error-overlay@^6.0.11:
@@ -9615,7 +9608,7 @@ tslib@^1.8.1:
96159608
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
96169609
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==
96179610

9618-
tslib@^2.0.3, tslib@^2.7.0, tslib@^2.8.0:
9611+
tslib@^2.0.3, tslib@^2.8.0:
96199612
version "2.8.1"
96209613
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.8.1.tgz#612efe4ed235d567e8aba5f2a5fab70280ade83f"
96219614
integrity sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==

0 commit comments

Comments
 (0)