From ab86ecf90e5376c529163975f949ef1fcd30dd92 Mon Sep 17 00:00:00 2001 From: Abhinav Adduri Date: Wed, 31 May 2017 09:57:02 -0700 Subject: [PATCH] pull request changes --- app.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app.js b/app.js index ca02cf51..c2140a08 100644 --- a/app.js +++ b/app.js @@ -26,12 +26,17 @@ app.get('/assets/download/:id', function(req, res) { let id = req.params.id; client.hget(id, "filename", function(err, reply) { // maybe some expiration logic too if (!reply) { - res.send('This link has expired!'); + res.sendStatus(404); } else { res.setHeader('Content-Disposition', 'attachment; filename=' + reply); res.setHeader('Content-Type', 'application/octet-stream'); - client.del(id); - res.download(__dirname + '/static/' + id, reply); + + res.download(__dirname + '/static/' + id, reply, function(err) { + if (!err) { + client.del(id); + fs.unlink(__dirname + '/static/' + id); + } + }); } })