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,
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;
private async uploadFile(collectionUuid: string, file: File, fileId: number, onProgress: UploadProgress = () => { return; }) {
const fileURL = `c=${collectionUuid}/${file.name}`;
- const fileContent = await fileToArrayBuffer(file);
const requestConfig = {
headers: {
'Content-Type': 'text/octet-stream'
onProgress(fileId, e.loaded, e.total, Date.now());
}
};
- return this.webdavClient.put(fileURL, fileContent, requestConfig);
-
+ return this.webdavClient.upload(fileURL, '', [file], requestConfig);
}
update(uuid: string, data: Partial<CollectionResource>) {
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';
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<any>(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<any>(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
+ }));
+ }
}
};
hideDuration: 2000,
kind: SnackbarKind.ERROR
}));
- dispatch(progressIndicatorActions.STOP_WORKING(COLLECTION_UPLOAD_FILES_DIALOG));
+ dispatch(progressIndicatorActions.STOP_WORKING(COLLECTION_UPLOAD_FILES_DIALOG));
}
}
};