Merge branch 'master' into 14015-rename-a-file
[arvados-workbench2.git] / src / services / collection-service / collection-service.ts
index c611f3668d9637917b6e7f02c2c4b97ef5d6d012..1c62ec5a68b471b89e646e6d698d99b423a421b8 100644 (file)
@@ -2,15 +2,15 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import { CommonResourceService } from "../../common/api/common-resource-service";
-import { CollectionResource } from "../../models/collection";
+import { CommonResourceService } from "~/common/api/common-resource-service";
+import { CollectionResource } from "~/models/collection";
 import { AxiosInstance } from "axios";
-import { CollectionFile, CollectionDirectory } from "../../models/collection-file";
-import { WebDAV } from "../../common/webdav";
+import { CollectionFile, CollectionDirectory } from "~/models/collection-file";
+import { WebDAV } from "~/common/webdav";
 import { AuthService } from "../auth-service/auth-service";
-import { mapTreeValues } from "../../models/tree";
+import { mapTreeValues } from "~/models/tree";
 import { parseFilesResponse } from "./collection-service-files-response";
-import { fileToArrayBuffer } from "../../common/file";
+import { fileToArrayBuffer } from "~/common/file";
 
 export type UploadProgress = (fileId: number, loaded: number, total: number, currentTime: number) => void;
 
@@ -28,16 +28,26 @@ export class CollectionService extends CommonResourceService<CollectionResource>
         return Promise.reject();
     }
 
-    async deleteFile(collectionUuid: string, filePath: string) {
-        return this.webdavClient.delete(`/c=${collectionUuid}${filePath}`);
+    async deleteFiles(collectionUuid: string, filePaths: string[]) {
+        for (const path of filePaths) {
+            await this.webdavClient.delete(`/c=${collectionUuid}${path}`);
+        }
     }
 
     async uploadFiles(collectionUuid: string, files: File[], onProgress?: UploadProgress) {
+        // files have to be uploaded sequentially
         for (let idx = 0; idx < files.length; idx++) {
             await this.uploadFile(collectionUuid, files[idx], idx, onProgress);
         }
     }
 
+    moveFile(collectionUuid: string, oldPath: string, newPath: string) {
+        return this.webdavClient.move(
+            `/c=${collectionUuid}${oldPath}`,
+            `/c=${collectionUuid}${encodeURI(newPath)}`
+        );
+    }
+
     private extendFileURL = (file: CollectionDirectory | CollectionFile) => ({
         ...file,
         url: this.webdavClient.defaults.baseURL + file.url + '?api_token=' + this.authService.getApiToken()