diff --git a/app.js b/app.js index 143a5012..ca02cf51 100644 --- a/app.js +++ b/app.js @@ -26,12 +26,12 @@ 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.send('This link has expired!'); } else { res.setHeader('Content-Disposition', 'attachment; filename=' + reply); res.setHeader('Content-Type', 'application/octet-stream'); - - res.download(__dirname + '/static/' + reply); + client.del(id); + res.download(__dirname + '/static/' + id, reply); } }) @@ -46,13 +46,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 @@ -Page Title +Download your file diff --git a/public/file.js b/public/file.js index ba4fe29f..8ac3ac63 100644 --- a/public/file.js +++ b/public/file.js @@ -44,11 +44,13 @@ function download() { var downloadUrl = URL.createObjectURL(blob); var a = document.createElement("a"); a.href = downloadUrl; - a.download = xhr.getResponseHeader('Content-Disposition').match(/filename="(.+)"/)[1];; + a.download = xhr.getResponseHeader('Content-Disposition').match(/filename="(.+)"/)[1]; + console.log(xhr.getResponseHeader('Content-Disposition')); document.body.appendChild(a); a.click(); }) .catch(function(err){ + alert('This link is either invalid or has expired.'); console.error(err); }); }) diff --git a/public/index.html b/public/index.html index c2df9da1..8de58241 100644 --- a/public/index.html +++ b/public/index.html @@ -1,7 +1,7 @@ -Page Title +Firefox Fileshare diff --git a/static/info.txt b/static/info.txt index 30d83303..b3119bbf 100644 --- a/static/info.txt +++ b/static/info.txt @@ -1 +1 @@ -This is where files will go. +This is where downloaded files are stored.