| Adding the total seeders and leechers over all torrents - seedlinux - Torrent i… | |
| Log | |
| Files | |
| Refs | |
| README | |
| --- | |
| commit 2f35008b9493392a9c01e92326e2fcee14143610 | |
| parent 2c1f07d8758c02242cdf0843b296b89e24005c59 | |
| Author: Jay Scott <[email protected]> | |
| Date: Wed, 5 Jul 2017 21:12:25 +0100 | |
| Adding the total seeders and leechers over all torrents | |
| Diffstat: | |
| M controllers/torrents_controller.js | 22 ++++++++++++++++++++++ | |
| M views/layout.pug | 4 ++-- | |
| 2 files changed, 24 insertions(+), 2 deletions(-) | |
| --- | |
| diff --git a/controllers/torrents_controller.js b/controllers/torrents_controll… | |
| @@ -3,6 +3,24 @@ | |
| const Torrent = require('../models/torrent_model'); | |
| const async = require('async'); | |
| +function getCount(callback) { | |
| + | |
| + Torrent.aggregate([ | |
| + { $group: { | |
| + _id: null, | |
| + total_seeders: { $sum: "$seeders" }, | |
| + total_leechers: { $sum: "$leechers" } | |
| + }} | |
| + ], function (err, result) { | |
| + if (err) { | |
| + callback(err,null); | |
| + } else { | |
| + callback(null, result[0]); | |
| + } | |
| + }); | |
| + | |
| +} | |
| + | |
| function getTorrent(query, callback) { | |
| Torrent.find(query, function(err, data) { | |
| if (err) { | |
| @@ -23,6 +41,7 @@ function saveTorrent(query, data, callback) { | |
| }); | |
| } | |
| + | |
| function updateTorrent(torrent, callback) { | |
| const webtorrentHealth = require('webtorrent-health'); | |
| @@ -49,6 +68,9 @@ exports.index = function(req, res) { | |
| }, | |
| torrent_data: function(callback) { | |
| Torrent.find({}, callback); | |
| + }, | |
| + torrent_seeds: function(callback) { | |
| + getCount(callback); | |
| } | |
| }, | |
| function(err, results) { | |
| diff --git a/views/layout.pug b/views/layout.pug | |
| @@ -19,10 +19,10 @@ html | |
| .value= data.torrent_count | |
| .label= "Total Torrents" | |
| .red.statistic | |
| - .value= "23" | |
| + .value= data.torrent_seeds.total_seeders | |
| .label= "Seeders" | |
| .violet.statistic | |
| - .value= "231" | |
| + .value= data.torrent_seeds.total_leechers | |
| .label= "Leechers" | |
| .ui.divider |