| Cleaning up torrent controller, adding download of torrent. - seedlinux - Torre… | |
| Log | |
| Files | |
| Refs | |
| README | |
| --- | |
| commit 0f971f44146d48c4f29105a4b7429b591923320d | |
| parent 57d0cce46fd2d49dee954b65f06d03a2df688003 | |
| Author: Jay Scott <[email protected]> | |
| Date: Thu, 6 Jul 2017 15:29:15 +0100 | |
| Cleaning up torrent controller, adding download of torrent. | |
| Diffstat: | |
| M controllers/torrents_controller.js | 30 ++++++++++++++++++++++++++++-- | |
| M routes/index.js | 5 +++-- | |
| M views/torrent.pug | 2 +- | |
| 3 files changed, 32 insertions(+), 5 deletions(-) | |
| --- | |
| diff --git a/controllers/torrents_controller.js b/controllers/torrents_controll… | |
| @@ -60,6 +60,32 @@ function updateTorrent(torrent, callback) { | |
| }); | |
| } | |
| +exports.download = function(req, res) { | |
| + | |
| + const torrentFolder = './data/torrents/'; | |
| + | |
| + async.waterfall([ | |
| + function(callback){ | |
| + getTorrent({hash: req.params.id }, function(err, torrent) { | |
| + if (err) callback(true); | |
| + | |
| + if (!torrent) | |
| + callback("404"); | |
| + else | |
| + callback(null, torrent); | |
| + }); | |
| + }], function (err, data) { | |
| + | |
| + if (err === "404") | |
| + res.sendStatus(404); | |
| + else if (err) | |
| + res.sendStatus(500); | |
| + else | |
| + res.download(torrentFolder + data.name + '.torrent'); | |
| + } | |
| + ); | |
| +}; | |
| + | |
| exports.index = function(req, res) { | |
| async.parallel( | |
| { | |
| @@ -79,7 +105,7 @@ exports.index = function(req, res) { | |
| ); | |
| }; | |
| -exports.torrent_detail = function(req, res) { | |
| +exports.detail = function(req, res) { | |
| async.parallel( | |
| { | |
| torrent_count: function(callback) { | |
| @@ -102,7 +128,7 @@ exports.torrent_detail = function(req, res) { | |
| ); | |
| }; | |
| -exports.torrent_update = function(req, res) { | |
| +exports.update = function(req, res) { | |
| async.waterfall([ | |
| function(callback){ | |
| diff --git a/routes/index.js b/routes/index.js | |
| @@ -5,6 +5,7 @@ const router = express.Router(); | |
| const torrent_controller = require('../controllers/torrents_controller'); | |
| router.get('/', torrent_controller.index); | |
| -router.get('/details/:id', torrent_controller.torrent_detail); | |
| -router.get('/update/:id', torrent_controller.torrent_update); | |
| +router.get('/details/:id', torrent_controller.detail); | |
| +router.get('/update/:id', torrent_controller.update); | |
| +router.get('/download/:id', torrent_controller.download); | |
| module.exports = router; | |
| diff --git a/views/torrent.pug b/views/torrent.pug | |
| @@ -11,7 +11,7 @@ mixin status(torrent) | |
| i.magnet.olive.icon | |
| a(href="" + torrent.magneturi)= "Magnet" | |
| i.barcode.olive.icon | |
| - a(href="")= "Torrent" | |
| + a(href="/download/" + torrent.hash)= "Torrent" | |
| block content | |
| table.ui.sortable.selectable.very.compact.olive.table |