From 2de62809f717c64091505a01961b517ee6ccc9d4 Mon Sep 17 00:00:00 2001 From: Daniel Kos Date: Tue, 20 Nov 2018 00:20:48 +0100 Subject: [PATCH] Replace loading -> upload with streamed upload, fix reporting error on file remove Bug #14310 Arvados-DCO-1.1-Signed-off-by: Daniel Kos --- src/common/webdav.ts | 34 +++++++++++++++++-- .../collection-service/collection-service.ts | 4 +-- .../collection-panel-files-actions.ts | 18 +++++++--- .../collections/collection-upload-actions.ts | 2 +- 4 files changed, 46 insertions(+), 12 deletions(-) diff --git a/src/common/webdav.ts b/src/common/webdav.ts index 27e1f22d..8aea568a 100644 --- a/src/common/webdav.ts +++ b/src/common/webdav.ts @@ -25,9 +25,23 @@ export class WebDAV { this.request({ ...config, url, method: 'PUT', - data, + data }) + upload = (url: string, path: string, files: File[], config: WebDAVRequestConfig = {}) => { + const fd = new FormData(); + fd.append('path', path); + files.forEach((f, idx) => { + fd.append(`file-${idx}`, f); + }); + + return this.request({ + ...config, url, + method: 'PUT', + data: fd + }); + } + copy = (url: string, destination: string, config: WebDAVRequestConfig = {}) => this.request({ ...config, url, @@ -62,13 +76,27 @@ export class WebDAV { r.upload.addEventListener('progress', config.onUploadProgress); } - r.addEventListener('load', () => resolve(r)); - r.addEventListener('error', () => reject(r)); + r.addEventListener('load', () => { + if (r.status === 404) { + return reject(r); + } else { + return resolve(r); + } + }); + + r.addEventListener('error', () => { + return reject(r); + }); + + r.upload.addEventListener('error', () => { + return reject(r); + }); r.send(config.data); }); } } + export interface WebDAVRequestConfig { headers?: { [key: string]: string; diff --git a/src/services/collection-service/collection-service.ts b/src/services/collection-service/collection-service.ts index 00ba8547..b0d5cb14 100644 --- a/src/services/collection-service/collection-service.ts +++ b/src/services/collection-service/collection-service.ts @@ -62,7 +62,6 @@ export class CollectionService extends TrashableResourceService { return; }) { const fileURL = `c=${collectionUuid}/${file.name}`; - const fileContent = await fileToArrayBuffer(file); const requestConfig = { headers: { 'Content-Type': 'text/octet-stream' @@ -71,8 +70,7 @@ export class CollectionService extends TrashableResourceService) { diff --git a/src/store/collection-panel/collection-panel-files/collection-panel-files-actions.ts b/src/store/collection-panel/collection-panel-files/collection-panel-files-actions.ts index 4764d436..6ee5ca0d 100644 --- a/src/store/collection-panel/collection-panel-files/collection-panel-files-actions.ts +++ b/src/store/collection-panel/collection-panel-files/collection-panel-files-actions.ts @@ -7,7 +7,7 @@ import { Dispatch } from "redux"; import { CollectionFilesTree, CollectionFileType } from "~/models/collection-file"; import { ServiceRepository } from "~/services/services"; import { RootState } from "../../store"; -import { snackbarActions } from "../../snackbar/snackbar-actions"; +import { snackbarActions, SnackbarKind } from "../../snackbar/snackbar-actions"; import { dialogActions } from '../../dialog/dialog-actions'; import { getNodeValue } from "~/models/tree"; import { filterCollectionFilesBySelection } from './collection-panel-files-state'; @@ -37,10 +37,18 @@ export const removeCollectionFiles = (filePaths: string[]) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { const currentCollection = getState().collectionPanel.item; if (currentCollection) { - dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Removing ...' })); - await services.collectionService.deleteFiles(currentCollection.uuid, filePaths); - dispatch(loadCollectionFiles(currentCollection.uuid)); - dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Removed.', hideDuration: 2000 })); + dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Removing...' })); + try { + await services.collectionService.deleteFiles(currentCollection.uuid, filePaths); + dispatch(loadCollectionFiles(currentCollection.uuid)); + dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Removed.', hideDuration: 2000 })); + } catch (e) { + dispatch(snackbarActions.OPEN_SNACKBAR({ + message: 'Could not remove file.', + hideDuration: 2000, + kind: SnackbarKind.ERROR + })); + } } }; diff --git a/src/store/collections/collection-upload-actions.ts b/src/store/collections/collection-upload-actions.ts index c410cf04..cf8c37c8 100644 --- a/src/store/collections/collection-upload-actions.ts +++ b/src/store/collections/collection-upload-actions.ts @@ -52,7 +52,7 @@ export const submitCollectionFiles = () => hideDuration: 2000, kind: SnackbarKind.ERROR })); - dispatch(progressIndicatorActions.STOP_WORKING(COLLECTION_UPLOAD_FILES_DIALOG)); + dispatch(progressIndicatorActions.STOP_WORKING(COLLECTION_UPLOAD_FILES_DIALOG)); } } }; -- 2.30.2