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 0aa7c7ee8ec64414271157071c92c517c035b9ba
parent b53ead819f1dadf8b2cb9ad515eda74871883914
Author: Jay Scott <jay@jayscott.co.uk>
Date:   Wed,  5 Jul 2017 21:12:25 +0100

Adding the total seeders and leechers over all torrents

Diffstat:
Mcontrollers/torrents_controller.js | 22++++++++++++++++++++++
Mviews/layout.pug | 4++--
2 files changed, 24 insertions(+), 2 deletions(-)

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