2015-06-11 06:02:46 +02:00
|
|
|
upload.modules.addmodule({
|
|
|
|
name: 'updown',
|
|
|
|
init: function () {
|
2015-06-11 08:47:11 +02:00
|
|
|
|
2015-06-11 06:02:46 +02:00
|
|
|
},
|
|
|
|
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'
|
2015-06-11 08:47:11 +02:00
|
|
|
xhr.onerror = this.onerror.bind(this, progress)
|
2015-06-11 06:02:46 +02:00
|
|
|
xhr.addEventListener('progress', progress, false)
|
|
|
|
xhr.send()
|
|
|
|
},
|
2015-06-11 08:47:11 +02:00
|
|
|
onerror: function(progress) {
|
|
|
|
progress('error')
|
|
|
|
},
|
2015-06-11 06:02:46 +02:00
|
|
|
downloaded: function (seed, progress, done, response) {
|
2015-06-11 08:47:11 +02:00
|
|
|
if (response.target.status != 200) {
|
|
|
|
this.onerror(progress)
|
|
|
|
} else {
|
|
|
|
progress('decrypting')
|
|
|
|
crypt.decrypt(response.target.response, seed).done(done)
|
|
|
|
}
|
2015-06-11 06:02:46 +02:00
|
|
|
},
|
|
|
|
encrypted: function(progress, done, data) {
|
|
|
|
var formdata = new FormData()
|
|
|
|
formdata.append('privkey', 'c61540b5ceecd05092799f936e27755f')
|
|
|
|
formdata.append('ident', data.ident)
|
|
|
|
formdata.append('file', data.encrypted)
|
|
|
|
$.ajax({
|
|
|
|
url: (upload.config.server ? upload.config.server : '') + 'up',
|
|
|
|
data: formdata,
|
|
|
|
cache: false,
|
|
|
|
processData: false,
|
|
|
|
contentType: false,
|
|
|
|
dataType: 'json',
|
|
|
|
xhr: function () {
|
|
|
|
var xhr = new XMLHttpRequest()
|
|
|
|
xhr.upload.addEventListener('progress', progress, false)
|
|
|
|
return xhr
|
|
|
|
},
|
|
|
|
type: 'POST'
|
|
|
|
}).done(done.bind(undefined, data))
|
|
|
|
},
|
|
|
|
download: function (seed, progress, done) {
|
|
|
|
crypt.ident(seed).done(this.downloadfromident.bind(this, seed, progress, done))
|
|
|
|
},
|
|
|
|
upload: function (blob, progress, done) {
|
|
|
|
crypt.encrypt(blob).done(this.encrypted.bind(this, progress, done))
|
|
|
|
}
|
|
|
|
})
|