Merge branch '19783-picking-tweak' refs #19783
[arvados-workbench2.git] / src / common / webdav.ts
index ca3b6d74686093ad75b3776faa29499ca9684de6..d4f904ae9832461abd777e5c8f6a112c49d14e65 100644 (file)
@@ -2,7 +2,7 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import { customEncodeURI, encodeHash } from "./url";
+import { customEncodeURI } from "./url";
 
 export class WebDAV {
 
@@ -30,6 +30,12 @@ export class WebDAV {
             data
         })
 
+    get = (url: string, config: WebDAVRequestConfig = {}) =>
+        this.request({
+            ...config, url,
+            method: 'GET'
+        })
+
     upload = (url: string, files: File[], config: WebDAVRequestConfig = {}) => {
         return Promise.all(
             files.map(file => this.request({
@@ -79,15 +85,20 @@ export class WebDAV {
                     ? this.defaults.baseURL+'/'
                     : ''}${customEncodeURI(config.url)}`);
 
-            if (config.headers && config.headers.Destination && config.headers.Destination.indexOf('#') > -1) {
-                config.headers.Destination = encodeHash(config.headers.Destination);
-            }
-
             const headers = { ...this.defaults.headers, ...config.headers };
             Object
                 .keys(headers)
                 .forEach(key => r.setRequestHeader(key, headers[key]));
 
+            if (!(window as any).cancelTokens) {
+                Object.assign(window, { cancelTokens: {} });
+            }
+
+            (window as any).cancelTokens[config.url] = () => {
+                resolve(r);
+                r.abort();
+            }
+
             if (config.onUploadProgress) {
                 r.upload.addEventListener('progress', config.onUploadProgress);
             }
@@ -133,4 +144,4 @@ interface RequestConfig {
     headers?: { [key: string]: string };
     data?: any;
     onUploadProgress?: (event: ProgressEvent) => void;
-}
\ No newline at end of file
+}