+ return this.keepWebdavClient.upload(fileURL, [file], requestConfig);
+ }
+
+ deleteFiles(collectionUuid: string, files: string[], showErrors?: boolean) {
+ const optimizedFiles = files
+ .sort((a, b) => a.length - b.length)
+ .reduce((acc, currentPath) => {
+ const parentPathFound = acc.find(parentPath => currentPath.indexOf(`${parentPath}/`) > -1);
+
+ if (!parentPathFound) {
+ return [...acc, currentPath];
+ }
+
+ return acc;
+ }, []);
+
+ const fileMap = optimizedFiles.reduce((obj, filePath) => {
+ return {
+ ...obj,
+ [this.combineFilePath([filePath])]: "",
+ };
+ }, {});
+
+ return this.replaceFiles({ uuid: collectionUuid }, fileMap, showErrors);
+ }
+
+ copyFiles(
+ sourcePdh: string,
+ files: string[],
+ destinationCollection: CollectionPartialUpdateOrCreate,
+ destinationPath: string,
+ showErrors?: boolean
+ ) {
+ const fileMap = files.reduce((obj, sourceFile) => {
+ const fileBasename = sourceFile.split("/").filter(Boolean).slice(-1).join("");
+ return {
+ ...obj,
+ [this.combineFilePath([destinationPath, fileBasename])]: `${sourcePdh}${this.combineFilePath([sourceFile])}`,
+ };
+ }, {});
+
+ return this.replaceFiles(destinationCollection, fileMap, showErrors);
+ }
+
+ moveFiles(
+ sourceUuid: string,
+ sourcePdh: string,
+ files: string[],
+ destinationCollection: CollectionPartialUpdateOrCreate,
+ destinationPath: string,
+ showErrors?: boolean
+ ) {
+ if (sourceUuid === destinationCollection.uuid) {
+ let errors: CommonResourceServiceError[] = [];
+ const fileMap = files.reduce((obj, sourceFile) => {
+ const fileBasename = sourceFile.split("/").filter(Boolean).slice(-1).join("");
+ const fileDestinationPath = this.combineFilePath([destinationPath, fileBasename]);
+ const fileSourcePath = this.combineFilePath([sourceFile]);
+ const fileSourceUri = `${sourcePdh}${fileSourcePath}`;
+
+ if (fileDestinationPath !== fileSourcePath) {
+ return {
+ ...obj,
+ [fileDestinationPath]: fileSourceUri,
+ [fileSourcePath]: "",
+ };
+ } else {
+ errors.push(CommonResourceServiceError.SOURCE_DESTINATION_CANNOT_BE_SAME);
+ return obj;
+ }
+ }, {});
+
+ if (errors.length === 0) {
+ return this.replaceFiles({ uuid: sourceUuid }, fileMap, showErrors);
+ } else {
+ return Promise.reject({ errors });
+ }
+ } else {
+ return this.copyFiles(sourcePdh, files, destinationCollection, destinationPath, showErrors).then(() => {
+ return this.deleteFiles(sourceUuid, files, showErrors);
+ });
+ }
+ }
+
+ createDirectory(collectionUuid: string, path: string, showErrors?: boolean) {
+ const fileMap = { [this.combineFilePath([path])]: emptyCollectionPdh };
+
+ return this.replaceFiles({ uuid: collectionUuid }, fileMap, showErrors);