projects
/
arvados-workbench2.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
20029: Add collection batch file delete/copy/move and unit tests
[arvados-workbench2.git]
/
src
/
common
/
webdav.ts
diff --git
a/src/common/webdav.ts
b/src/common/webdav.ts
index ca3b6d74686093ad75b3776faa29499ca9684de6..c95d8747e5b495d45ca8400a348fb4cb89e1bfa7 100644
(file)
--- a/
src/common/webdav.ts
+++ b/
src/common/webdav.ts
@@
-2,21
+2,33
@@
//
// SPDX-License-Identifier: AGPL-3.0
//
// SPDX-License-Identifier: AGPL-3.0
-import { customEncodeURI
, encodeHash
} from "./url";
+import { customEncodeURI } from "./url";
export class WebDAV {
export class WebDAV {
- defaults: WebDAVDefaults = {
+
private
defaults: WebDAVDefaults = {
baseURL: '',
baseURL: '',
- headers: {},
+ headers: {
+ 'Cache-Control': 'must-revalidate'
+ },
};
constructor(config?: Partial<WebDAVDefaults>, private createRequest = () => new XMLHttpRequest()) {
if (config) {
};
constructor(config?: Partial<WebDAVDefaults>, private createRequest = () => new XMLHttpRequest()) {
if (config) {
- this.defaults = { ...this.defaults, ...config };
+ this.defaults = {
+ ...this.defaults,
+ ...config,
+ headers: {
+ ...this.defaults.headers,
+ ...config.headers
+ },
+ };
}
}
}
}
+ getBaseUrl = (): string => this.defaults.baseURL;
+ setAuthorization = (token?) => this.defaults.headers.Authorization = token;
+
propfind = (url: string, config: WebDAVRequestConfig = {}) =>
this.request({
...config, url,
propfind = (url: string, config: WebDAVRequestConfig = {}) =>
this.request({
...config, url,
@@
-30,6
+42,12
@@
export class WebDAV {
data
})
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({
upload = (url: string, files: File[], config: WebDAVRequestConfig = {}) => {
return Promise.all(
files.map(file => this.request({
@@
-70,6
+88,15
@@
export class WebDAV {
method: 'DELETE'
})
method: 'DELETE'
})
+ mkdir = (url: string, config: WebDAVRequestConfig = {}) =>
+ this.request({
+ ...config, url,
+ method: 'MKCOL',
+ headers: {
+ ...config.headers,
+ }
+ })
+
private request = (config: RequestConfig) => {
return new Promise<XMLHttpRequest>((resolve, reject) => {
const r = this.createRequest();
private request = (config: RequestConfig) => {
return new Promise<XMLHttpRequest>((resolve, reject) => {
const r = this.createRequest();
@@
-79,15
+106,20
@@
export class WebDAV {
? this.defaults.baseURL+'/'
: ''}${customEncodeURI(config.url)}`);
? 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]));
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);
}
if (config.onUploadProgress) {
r.upload.addEventListener('progress', config.onUploadProgress);
}
@@
-133,4
+165,4
@@
interface RequestConfig {
headers?: { [key: string]: string };
data?: any;
onUploadProgress?: (event: ProgressEvent) => void;
headers?: { [key: string]: string };
data?: any;
onUploadProgress?: (event: ProgressEvent) => void;
-}
\ No newline at end of file
+}