projects
/
arvados-workbench2.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
20029: Refactor replaceFiles operations
[arvados-workbench2.git]
/
src
/
common
/
webdav.ts
diff --git
a/src/common/webdav.ts
b/src/common/webdav.ts
index 8d071fa635ce2f0dc58085e447f981191d96e8a7..bb8a68bdd221e1733d42f0f64b8c61e434863304 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({
@@
-79,15
+97,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 = 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
+156,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
+}