diff --git a/app.js b/app.js index 143a5012..43cad4bf 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('error'); + res.sendStatus(404); } else { res.setHeader('Content-Disposition', 'attachment; filename=' + reply); res.setHeader('Content-Type', 'application/octet-stream'); - - res.download(__dirname + '/static/' + reply); + + res.download(__dirname + '/static/' + id, reply, function(err) { + if (!err) { + client.del(id); + fs.unlinkSync(__dirname + '/static/' + id); + } + }); } }) @@ -46,13 +51,14 @@ app.route('/upload/:id') console.log("Uploading: " + filename); //Path where image will be uploaded - fstream = fs.createWriteStream(__dirname + '/static/' + filename); + fstream = fs.createWriteStream(__dirname + '/static/' + req.params.id); file.pipe(fstream); fstream.on('close', function () { let id = req.params.id; client.hset(id, "filename", filename, redis.print); client.hset(id, "expiration", 0, redis.print); - console.log("Upload Finished of " + filename); + client.expire(id, 86400000); + console.log("Upload Finished of " + filename); res.send(id); }); }); diff --git a/public/download.html b/public/download.html index 57c6b6bf..c301659f 100644 --- a/public/download.html +++ b/public/download.html @@ -1,7 +1,7 @@
-