port fix for #1005 to vnext

This commit is contained in:
Danny Coates 2018-11-16 13:33:40 -08:00
parent 4ef303a2c9
commit b6517c5442
No known key found for this signature in database
GPG key ID: 4C442633C62E00CB
4 changed files with 10 additions and 20 deletions

View file

@ -6,14 +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 fileStream = await storage.get(id);
let cancelled = false;
@ -22,7 +14,7 @@ module.exports = async function(req, res) {
fileStream.destroy();
});
fileStream.on('end', async () => {
fileStream.pipe(res).on('finish', async () => {
if (cancelled) {
return;
}
@ -39,8 +31,6 @@ module.exports = async function(req, res) {
log.info('StorageError:', id);
}
});
fileStream.pipe(res);
} catch (e) {
res.sendStatus(404);
}