Cleaning up torrent controller, adding download of torrent. - seedlinux - Torrent indexing tool opensource torrents with share ratio's etc.
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
       ---
 (DIR) commit 0f971f44146d48c4f29105a4b7429b591923320d
 (DIR) parent 57d0cce46fd2d49dee954b65f06d03a2df688003
 (HTM) Author: Jay Scott <me@jay.scot>
       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(-)
       ---
 (DIR) 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){
 (DIR) 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;
 (DIR) 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