X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/2de62809f717c64091505a01961b517ee6ccc9d4..e4395f2bfb2a271303e9dc7f91bec6c890e792e3:/src/common/webdav.ts diff --git a/src/common/webdav.ts b/src/common/webdav.ts index 8aea568a..17032768 100644 --- a/src/common/webdav.ts +++ b/src/common/webdav.ts @@ -28,32 +28,38 @@ export class WebDAV { data }) - upload = (url: string, path: string, files: File[], config: WebDAVRequestConfig = {}) => { - const fd = new FormData(); - fd.append('path', path); - files.forEach((f, idx) => { - fd.append(`file-${idx}`, f); - }); - - return this.request({ - ...config, url, - method: 'PUT', - data: fd - }); + upload = (url: string, files: File[], config: WebDAVRequestConfig = {}) => { + return Promise.all( + files.map(file => this.request({ + ...config, url, + method: 'PUT', + data: file + })) + ); } copy = (url: string, destination: string, config: WebDAVRequestConfig = {}) => this.request({ ...config, url, method: 'COPY', - headers: { ...config.headers, Destination: this.defaults.baseURL + destination } + headers: { + ...config.headers, + Destination: this.defaults.baseURL + ? this.defaults.baseURL.replace(/\/+$/, '') + '/' + destination.replace(/^\/+/, '') + : destination + } }) move = (url: string, destination: string, config: WebDAVRequestConfig = {}) => this.request({ ...config, url, method: 'MOVE', - headers: { ...config.headers, Destination: this.defaults.baseURL + destination } + headers: { + ...config.headers, + Destination: this.defaults.baseURL + ? this.defaults.baseURL.replace(/\/+$/, '') + '/' + destination.replace(/^\/+/, '') + : destination + } }) delete = (url: string, config: WebDAVRequestConfig = {}) => @@ -65,8 +71,11 @@ export class WebDAV { private request = (config: RequestConfig) => { return new Promise((resolve, reject) => { const r = this.createRequest(); - r.open(config.method, this.defaults.baseURL + config.url); - + this.defaults.baseURL = this.defaults.baseURL.replace(/\/+$/, ''); + r.open(config.method, + `${this.defaults.baseURL + ? this.defaults.baseURL+'/' + : ''}${config.url}`); const headers = { ...this.defaults.headers, ...config.headers }; Object .keys(headers) @@ -115,4 +124,4 @@ interface RequestConfig { headers?: { [key: string]: string }; data?: any; onUploadProgress?: (event: ProgressEvent) => void; -} +} \ No newline at end of file