fixed #15;added support for downloading via bittorrent files;added new class for getting download statistics

This commit is contained in:
huangjx
2021-10-21 18:18:41 +08:00
parent c2ce945aad
commit 5037180a40
12 changed files with 190 additions and 36 deletions

View File

@@ -14,12 +14,16 @@ const Http = class {
this.data = data
return this
}
setDataType($value) {
this.dataType = $value;
}
send() {
let token = this.getToken();
this.xhr.open(this.method, this.url);
this.xhr.setRequestHeader('requesttoken', token)
this.xhr.setRequestHeader('OCS-APIREQUEST', 'true')
this.xhr.setRequestHeader('Content-Type', this.dataType);
if (this.dataType)
this.xhr.setRequestHeader('Content-Type', this.dataType);
let callback = this.handler;
this.xhr.onload = () => {
if (typeof callback === 'function')
@@ -47,6 +51,17 @@ const Http = class {
this.errorHandler = handler
return this;
}
upload(file) {
const fd = new FormData();
this.xhr.open(this.method, this.url, true);
let callback = this.handler;
this.xhr.onload = () => {
if (typeof callback === 'function')
callback(JSON.parse(this.xhr.response));
}
fd.append('torrentfile', file);
return this.xhr.send(fd);
}
}
export default Http