Redirect when hash lookup results nothing - seedlinux - Torrent indexing tool opensource torrents with share ratio's etc.
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
       ---
 (DIR) commit 92e6b8709b18cfcc5db7755068d2ed843f9ca002
 (DIR) parent 822f48597fe37b14645e5c936e133620a16ffd56
 (HTM) Author: Jay Scott <me@jay.scot>
       Date:   Fri, 30 Jun 2017 13:01:49 +0100
       
       Redirect when hash lookup results nothing
       
       Diffstat:
         M controllers/torrents_controller.js  |      13 +++++++------
         M models/torrent_model.js             |       2 ++
       
       2 files changed, 9 insertions(+), 6 deletions(-)
       ---
 (DIR) diff --git a/controllers/torrents_controller.js b/controllers/torrents_controller.js
       @@ -13,11 +13,7 @@ exports.index = function(req, res) {
                    Torrent.find({},callback);
                },
            }, function(err, results) {
       -        if(!results) {
       -          console.log(results.torrent_count);
       -          results.torrent_count == 0;
       -        }
       -        res.render('torrent', { title: 'Index Page', error: err, data: results });
       +        res.render('torrent', { title: 'Index Page', data: results });
            });
        };
        
       @@ -30,6 +26,11 @@ exports.torrent_detail = function(req, res) {
                  Torrent.find({hash: req.params.id},callback);
              },
            }, function(err, results) {
       -        res.render('details', { title: 'Torrent Details', error: err, data: results });
       +        if(results.torrent_data == "" ) {
       +          console.log(results);
       +          res.redirect('/torrent');
       +        } else {
       +            res.render('details', { title: 'Torrent Details', data: results });
       +          }
            });
        };
 (DIR) diff --git a/models/torrent_model.js b/models/torrent_model.js
       @@ -3,6 +3,8 @@
        const mongoose = require('mongoose');
        const Schema = mongoose.Schema;
        
       +mongoose.Promise = global.Promise;
       +
        const TorrentSchema = Schema(
          {
            name: {type: String, required: true, max: 100},