[ARVADOS-WORKBENCH2] created: 1.1.4-572-g1c42304

Git user git at public.curoverse.com
Thu Aug 9 08:52:11 EDT 2018


        at  1c42304ed00d0055e24070793e0cef08a7c76c97 (commit)


commit 1c42304ed00d0055e24070793e0cef08a7c76c97
Author: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
Date:   Thu Aug 9 14:52:01 2018 +0200

    Implement simple webdav client
    
    Feature #13989
    
    Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski at contractors.roche.com>

diff --git a/src/common/webdav.ts b/src/common/webdav.ts
new file mode 100644
index 0000000..5c7f9d2
--- /dev/null
+++ b/src/common/webdav.ts
@@ -0,0 +1,109 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+export class WebDAV {
+    static create(config?: Partial<WebDAVDefaults>) {
+        return new WebDAV(config);
+    }
+
+    defaults: WebDAVDefaults = {
+        baseUrl: '',
+        headers: {},
+    };
+
+    propfind = (url: string, config: PropfindConfig = {}) =>
+        this.request({
+            ...config, url,
+            method: 'PROPFIND'
+        })
+
+    put = (url: string, config: PutConfig = {}) =>
+        this.request({
+            ...config, url,
+            method: 'PUT'
+        })
+
+    copy = (url: string, { destination, ...config }: CopyConfig) =>
+        this.request({
+            ...config, url,
+            method: 'COPY',
+            headers: { ...config.headers, Destination: this.defaults.baseUrl + destination }
+        })
+
+    move = (url: string, { destination, ...config }: MoveConfig) =>
+        this.request({
+            ...config, url,
+            method: 'MOVE',
+            headers: { ...config.headers, Destination: this.defaults.baseUrl + destination }
+        })
+
+    delete = (url: string, config: DeleteConfig = {}) =>
+        this.request({
+            ...config, url,
+            method: 'DELETE'
+        })
+
+    private constructor(config?: Partial<WebDAVDefaults>) {
+        if (config) {
+            this.defaults = { ...this.defaults, ...config };
+        }
+    }
+
+    private request = (config: RequestConfig) => {
+        return new Promise<XMLHttpRequest>((resolve, reject) => {
+            const r = new XMLHttpRequest();
+            r.open(config.method, this.defaults.baseUrl + config.url);
+
+            const headers = { ...this.defaults.headers, ...config.headers };
+            Object
+                .keys(headers)
+                .forEach(key => r.setRequestHeader(key, headers[key]));
+
+            if (config.onProgress) {
+                r.addEventListener('progress', config.onProgress);
+            }
+
+            r.addEventListener('load', () => resolve(r));
+            r.addEventListener('error', () => reject(r));
+
+            r.send(config.data);
+        });
+
+    }
+}
+
+export interface PropfindConfig extends BaseConfig { }
+
+export interface PutConfig extends BaseConfig {
+    data?: any;
+}
+
+export interface CopyConfig extends BaseConfig {
+    destination: string;
+}
+
+export interface MoveConfig extends BaseConfig {
+    destination: string;
+}
+
+export interface DeleteConfig extends BaseConfig { }
+
+interface BaseConfig {
+    headers?: {
+        [key: string]: string;
+    };
+}
+
+interface WebDAVDefaults {
+    baseUrl: string;
+    headers: { [key: string]: string };
+}
+
+interface RequestConfig {
+    method: string;
+    url: string;
+    headers?: { [key: string]: string };
+    data?: any;
+    onProgress?: (event: ProgressEvent) => void;
+}

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list