X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/5642c48285c296aa3b77760ed5d1431ccdb0f2f3..21d7f6cb32902073193db810b4dfad85d9cdff7e:/src/common/webdav.ts diff --git a/src/common/webdav.ts b/src/common/webdav.ts index 0b77f8c332..d4f904ae98 100644 --- a/src/common/webdav.ts +++ b/src/common/webdav.ts @@ -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,17 +85,20 @@ export class WebDAV { ? this.defaults.baseURL+'/' : ''}${customEncodeURI(config.url)}`); - if (config.headers && config.headers.Destination) { - const regexp = /(http[s]?:\/\/)?([^\/\s]+\/)(.*)/; - const match = decodeURIComponent(config.headers.Destination).match(regexp) || {}; - config.headers.Destination = `${match[1]}${match[2]}${customEncodeURI(match[3])}`; - } - 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); } @@ -135,4 +144,4 @@ interface RequestConfig { headers?: { [key: string]: string }; data?: any; onUploadProgress?: (event: ProgressEvent) => void; -} \ No newline at end of file +}