fixed #15;added support for downloading via bittorrent files;added new class for getting download statistics
This commit is contained in:
17
src/http.js
17
src/http.js
@@ -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
|
||||
Reference in New Issue
Block a user