stream download after headers

This commit is contained in:
Danny Coates 2017-06-07 17:03:03 -07:00
parent 82b71b2af7
commit 24abf669b0
No known key found for this signature in database
GPG Key ID: 4C442633C62E00CB
1 changed files with 9 additions and 10 deletions

View File

@ -63,19 +63,18 @@ app.get('/assets/download/:id', (req, res) => {
'Content-Type': 'application/octet-stream',
'Content-Length': contentLength
});
});
let file_stream = storage.get(id);
let file_stream = storage.get(id);
file_stream.on(notLocalHost ? 'finish' : 'close', () => {
storage.forceDelete(id).then(err => {
if (!err) {
console.log('Deleted.');
}
file_stream.on(notLocalHost ? 'finish' : 'close', () => {
storage.forceDelete(id).then(err => {
if (!err) {
console.log('Deleted.');
}
});
});
});
file_stream.pipe(res);
file_stream.pipe(res);
});
})
.catch(err => {
res.sendStatus(404);