Handle error
This commit is contained in:
parent
a600d0abbf
commit
5abf8edad5
2 changed files with 14 additions and 5 deletions
|
@ -21,7 +21,7 @@ upload.modules.addmodule({
|
|||
render: function (view) {
|
||||
view.html(this.template)
|
||||
this._ = {}
|
||||
|
||||
|
||||
this._.detailsarea = view.find('#downloaddetails')
|
||||
this._.filename = view.find('#downloaded_filename')
|
||||
this._.btns = view.find('#btnarea')
|
||||
|
@ -109,6 +109,8 @@ upload.modules.addmodule({
|
|||
progress: function (e) {
|
||||
if (e == 'decrypting') {
|
||||
this._.content.loading.text('Decrypting')
|
||||
} else if (e == 'error') {
|
||||
window.location.hash = '#'
|
||||
} else {
|
||||
var percent = (e.loaded / e.total) * 100
|
||||
this._.content.loading.text(Math.floor(percent) + '%')
|
||||
|
|
|
@ -1,20 +1,27 @@
|
|||
upload.modules.addmodule({
|
||||
name: 'updown',
|
||||
init: function () {
|
||||
|
||||
|
||||
},
|
||||
downloadfromident: function(seed, progress, done, ident) {
|
||||
var xhr = new XMLHttpRequest()
|
||||
xhr.onload = this.downloaded.bind(this, seed, progress, done)
|
||||
xhr.open('GET', (upload.config.server ? upload.config.server : '') + 'i/' + ident.ident)
|
||||
xhr.responseType = 'blob'
|
||||
//TODO: xhr.onerror = failed
|
||||
xhr.onerror = this.onerror.bind(this, progress)
|
||||
xhr.addEventListener('progress', progress, false)
|
||||
xhr.send()
|
||||
},
|
||||
onerror: function(progress) {
|
||||
progress('error')
|
||||
},
|
||||
downloaded: function (seed, progress, done, response) {
|
||||
progress('decrypting')
|
||||
crypt.decrypt(response.target.response, seed).done(done)
|
||||
if (response.target.status != 200) {
|
||||
this.onerror(progress)
|
||||
} else {
|
||||
progress('decrypting')
|
||||
crypt.decrypt(response.target.response, seed).done(done)
|
||||
}
|
||||
},
|
||||
encrypted: function(progress, done, data) {
|
||||
var formdata = new FormData()
|
||||
|
|
Loading…
Reference in a new issue