seedlinux

find open source torrents and stats for people wishing to contribute bandwidth.
git clone git://git.beardyjay.co.uk/seedlinux
Log | Files | Refs | README | LICENSE

commit fb544b9a9fb0779e943aa9d055cba9f798404b3f
parent c791a2a7b963a97ff71ebbff8269ba0ddc939714
Author: Jay Scott <jay@beardyjay.co.uk>
Date:   Thu,  6 Jul 2017 15:29:15 +0100

Cleaning up torrent controller, adding download of torrent.

Diffstat:
Mcontrollers/torrents_controller.js | 30++++++++++++++++++++++++++++--
Mroutes/index.js | 5+++--
Mviews/torrent.pug | 2+-
3 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/controllers/torrents_controller.js b/controllers/torrents_controller.js @@ -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