port fix for #1005 to vnext
This commit is contained in:
parent
4ef303a2c9
commit
b6517c5442
4 changed files with 10 additions and 20 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue