+
+ 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(collectionUuid, fileMap, showErrors);
+ }
+
+ copyFiles(sourcePdh: string, files: string[], destinationCollectionUuid: string, destinationPath: string, showErrors?: boolean) {
+ const fileMap = files.reduce((obj, sourceFile) => {
+ const sourceFileName = sourceFile.split("/").filter(Boolean).slice(-1).join("");
+ return {
+ ...obj,
+ [this.combineFilePath([destinationPath, sourceFileName])]: `${sourcePdh}${this.combineFilePath([sourceFile])}`,
+ };
+ }, {});
+
+ return this.replaceFiles(destinationCollectionUuid, fileMap, showErrors);
+ }
+
+ moveFiles(
+ sourceUuid: string,
+ sourcePdh: string,
+ files: string[],
+ destinationCollectionUuid: string,
+ destinationPath: string,
+ showErrors?: boolean
+ ) {
+ if (sourceUuid === destinationCollectionUuid) {
+ const fileMap = files.reduce((obj, sourceFile) => {
+ const sourceFileName = sourceFile.split("/").filter(Boolean).slice(-1).join("");
+ return {
+ ...obj,
+ [this.combineFilePath([destinationPath, sourceFileName])]: `${sourcePdh}${this.combineFilePath([sourceFile])}`,
+ [this.combineFilePath([sourceFile])]: "",
+ };
+ }, {});
+
+ return this.replaceFiles(sourceUuid, fileMap, showErrors);
+ } else {
+ return this.copyFiles(sourcePdh, files, destinationCollectionUuid, 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(collectionUuid, fileMap, showErrors);
+ }