diff --git a/app/api.js b/app/api.js index 99ba8bad..54c6eb9a 100644 --- a/app/api.js +++ b/app/api.js @@ -162,8 +162,8 @@ function download(id, keychain, onprogress, canceller) { }); xhr.addEventListener('progress', function(event) { - if (event.lengthComputable && event.target.status === 200) { - onprogress([event.loaded, event.total]); + if (event.target.status === 200) { + onprogress(event.loaded); } }); const auth = await keychain.authHeader(); @@ -171,7 +171,7 @@ function download(id, keychain, onprogress, canceller) { xhr.setRequestHeader('Authorization', auth); xhr.responseType = 'blob'; xhr.send(); - onprogress([0, 1]); + onprogress(0); }); } diff --git a/app/fileReceiver.js b/app/fileReceiver.js index 27dccf6d..23fc7567 100644 --- a/app/fileReceiver.js +++ b/app/fileReceiver.js @@ -47,7 +47,7 @@ export default class FileReceiver extends Nanobus { this.fileInfo.name = meta.name; this.fileInfo.type = meta.type; this.fileInfo.iv = meta.iv; - this.fileInfo.size = meta.size; + this.fileInfo.size = +meta.size; this.state = 'ready'; } @@ -57,7 +57,7 @@ export default class FileReceiver extends Nanobus { this.fileInfo.id, this.keychain, p => { - this.progress = p; + this.progress = [p, this.fileInfo.size]; this.emit('progress'); } ); diff --git a/server/routes/download.js b/server/routes/download.js index 8e1ecf98..c49c29ec 100644 --- a/server/routes/download.js +++ b/server/routes/download.js @@ -6,13 +6,6 @@ module.exports = async function(req, res) { const id = req.params.id; try { const meta = req.meta; - const contentLength = await storage.length(id); - res.writeHead(200, { - 'Content-Disposition': 'attachment', - 'Content-Type': 'application/octet-stream', - 'Content-Length': contentLength, - 'WWW-Authenticate': `send-v1 ${req.nonce}` - }); const file_stream = storage.get(id); let cancelled = false; @@ -21,7 +14,7 @@ module.exports = async function(req, res) { file_stream.destroy(); }); - file_stream.on('end', async () => { + file_stream.pipe(res).on('finish', async () => { if (cancelled) { return; } @@ -38,8 +31,6 @@ module.exports = async function(req, res) { log.info('StorageError:', id); } }); - - file_stream.pipe(res); } catch (e) { res.sendStatus(404); } diff --git a/server/storage/gcs.js b/server/storage/gcs.js index 8db209e7..1b7d0c5a 100644 --- a/server/storage/gcs.js +++ b/server/storage/gcs.js @@ -13,7 +13,7 @@ class GCSStorage { } getStream(id) { - return this.bucket.file(id).createReadStream(); + return this.bucket.file(id).createReadStream({ validation: false }); } set(id, file) {