feat(core): showing site info at footer

include users, torrents, seeders, leechers, uploaded, download etc.
This commit is contained in:
OldHawk
2017-08-16 11:38:14 +08:00
parent de3828598b
commit be62816ffc
9 changed files with 187 additions and 22 deletions

View File

@@ -577,6 +577,15 @@
//footer view
MIT_PROTOCOL: 'The source of this project is protected by <a href="https://github.com/twbs/bootstrap/blob/master/LICENSE" target="_blank">MIT</a> open source protocol',
GIT_REPO: 'Power by &copy;meanTottent<a href="https://github.com/taobataoma/meanTorrent" target="_blank">view on GitHub</a>',
TOTAL_USERS: 'Total Users',
TOTAL_TORRENTS: 'Total Torrents',
TOTAL_TORRENTSSIZE: 'Total TorrentsSize',
TOTAL_SEEDERS: 'Total Seeders',
TOTAL_LEECHERS: 'Total Leechers',
TOTAL_UPLOADED: 'Total Uploaded',
TOTAL_DOWNLOADED: 'Total Downloaded',
TOTAL_FORUMTOPICS: 'Total ForumTopics',
TOTAL_FORUMREPLIES: 'Total ForumReplies',
///////////////////////the movie db fields////////////////////////////////
TMDB_FIELDS: {

View File

@@ -577,6 +577,15 @@
//footer view
MIT_PROTOCOL: '本项目源码受 <a href="https://github.com/twbs/bootstrap/blob/master/LICENSE" target="_blank">MIT</a> 开源协议保护',
GIT_REPO: 'Power by &copy;meanTottent<a href="https://github.com/taobataoma/meanTorrent" target="_blank">GitHub 源码仓库</a>',
TOTAL_USERS: '注册会员',
TOTAL_TORRENTS: '种子数',
TOTAL_TORRENTSSIZE: '种子总体积',
TOTAL_SEEDERS: '正在做种',
TOTAL_LEECHERS: '正在下载',
TOTAL_UPLOADED: '总上传量',
TOTAL_DOWNLOADED: '总下载量',
TOTAL_FORUMTOPICS: '论坛话题',
TOTAL_FORUMREPLIES: '论坛回复',
///////////////////////the movie db fields////////////////////////////////
TMDB_FIELDS: {

View File

@@ -6,10 +6,10 @@
.controller('HeaderController', HeaderController);
HeaderController.$inject = ['$scope', '$state', '$stateParams', '$translate', 'Authentication', 'menuService', 'MeanTorrentConfig', 'localStorageService',
'ScoreLevelService', 'InvitationsService', '$interval', 'MessagesService'];
'ScoreLevelService', 'InvitationsService', '$interval', 'MessagesService', 'TorrentsService'];
function HeaderController($scope, $state, $stateParams, $translate, Authentication, menuService, MeanTorrentConfig, localStorageService, ScoreLevelService,
InvitationsService, $interval, MessagesService) {
InvitationsService, $interval, MessagesService, TorrentsService) {
var vm = this;
vm.user = Authentication.user;
vm.language = MeanTorrentConfig.meanTorrentConfig.language;
@@ -103,5 +103,14 @@
//});
}
};
/**
* getSiteInfo
*/
vm.getSiteInfo = function () {
TorrentsService.siteInfo(function (data) {
vm.siteInfo = data;
});
};
}
}());

View File

@@ -93,3 +93,11 @@ a:hover .header-profile-image {
margin-right: 15px;
}
.site-info {
border-bottom: solid 1px #222;
margin-bottom: 20px;
padding-bottom: 20px;
padding-top: 10px;
padding-left: 60px;
}

View File

@@ -1,22 +1,38 @@
<div class="container-fluid" style="padding-top: 15px; padding-bottom: 5px;" ng-controller="HeaderController as vm">
<div class="container-fluid" style="padding-top: 15px; padding-bottom: 5px;" ng-controller="HeaderController as vm" ng-init="vm.getSiteInfo();">
<div class="container">
<div class="row view-footer">
<div class="col-sm-7 col-sm-offset-1">
<ul>
<li>
<span class="lang-list lang-footer">
<span class="flag-icon {{l.class}}" title="{{l.title}}" ng-click="vm.changeLanguage(l.name);" ng-repeat="l in vm.language | orderBy: '-index'"></span>
</span>
</li>
<li translate="GIT_REPO"></li>
<li translate="MIT_PROTOCOL"></li>
</ul>
<div class="col-sm-10 col-sm-offset-1 site-info xs-hide">
<div class="row">
<div class="col-xs-6 col-sm-4 col-md-3">{{'TOTAL_USERS' | translate}}: {{vm.siteInfo.totalUsers}}</div>
<div class="col-xs-6 col-sm-4 col-md-3">{{'TOTAL_TORRENTS' | translate}}: {{vm.siteInfo.totalTorrents}}</div>
<div class="col-xs-6 col-sm-4 col-md-3">{{'TOTAL_TORRENTSSIZE' | translate}}: {{vm.siteInfo.totalTorrentsSize | bytes}}</div>
<div class="col-xs-6 col-sm-4 col-md-3">{{'TOTAL_SEEDERS' | translate}}: {{vm.siteInfo.totalSeeders}}</div>
<div class="col-xs-6 col-sm-4 col-md-3">{{'TOTAL_LEECHERS' | translate}}: {{vm.siteInfo.totalLeechers}}</div>
<div class="col-xs-6 col-sm-4 col-md-3">{{'TOTAL_UPLOADED' | translate}}: {{vm.siteInfo.totalUploaded | bytes}}</div>
<div class="col-xs-6 col-sm-4 col-md-3">{{'TOTAL_DOWNLOADED' | translate}}: {{vm.siteInfo.totalDownloaded | bytes}}</div>
<div class="col-xs-6 col-sm-4 col-md-3">{{'TOTAL_FORUMTOPICS' | translate}}: {{vm.siteInfo.totalForumTopics}}</div>
<div class="col-xs-6 col-sm-4 col-md-3">{{'TOTAL_FORUMREPLIES' | translate}}: {{vm.siteInfo.totalForumReplies}}</div>
</div>
</div>
<div class="col-sm-3 text-right">
<i class="icon ion-social-github"></i>
<i class="icon ion-social-nodejs"></i>
<i class="icon ion-social-html5-outline"></i>
<i class="icon ion-social-css3-outline"></i>
<div class="col-sm-12">
<div class="col-sm-7 col-sm-offset-1">
<ul>
<li>
<span class="lang-list lang-footer">
<span class="flag-icon {{l.class}}" title="{{l.title}}" ng-click="vm.changeLanguage(l.name);"
ng-repeat="l in vm.language | orderBy: '-index'"></span>
</span>
</li>
<li translate="GIT_REPO"></li>
<li translate="MIT_PROTOCOL"></li>
</ul>
</div>
<div class="col-sm-3 text-right">
<i class="icon ion-social-github"></i>
<i class="icon ion-social-nodejs"></i>
<i class="icon ion-social-html5-outline"></i>
<i class="icon ion-social-css3-outline"></i>
</div>
</div>
</div>
</div>

View File

@@ -60,6 +60,10 @@
params: {
torrentId: '@_id'
}
},
siteInfo: {
method: 'GET',
url: '/api/torrents/siteInfo'
}
});

View File

@@ -13,6 +13,8 @@ var path = require('path'),
Peer = mongoose.model('Peer'),
Thumb = mongoose.model('Thumb'),
Torrent = mongoose.model('Torrent'),
Forum = mongoose.model('Forum'),
Topic = mongoose.model('Topic'),
fs = require('fs'),
nt = require('nt'),
benc = require('bncode'),
@@ -797,6 +799,109 @@ exports.list = function (req, res) {
});
};
/**
* siteInfo - get site torrent info, seeders/leechers/torrents count/users etc.
* @param req
* @param res
*/
exports.siteInfo = function (req, res) {
var countUsers = function (callback) {
User.count(function (err, count) {
if (err) {
callback(err, null);
} else {
callback(null, count);
}
});
};
var countTorrents = function (callback) {
Torrent.count(function (err, count) {
if (err) {
callback(err, null);
} else {
callback(null, count);
}
});
};
var totalUpDown = function (callback) {
User.aggregate({
$group: {
_id: null,
uploaded: {$sum: '$uploaded'},
downloaded: {$sum: '$downloaded'}
}
}).exec(function (err, total) {
if (err) {
callback(err, null);
} else {
callback(null, total);
}
});
};
var totalTorrentsSize = function (callback) {
Torrent.aggregate({
$group: {
_id: null,
size: {$sum: '$torrent_size'},
seeders: {$sum: '$torrent_seeds'},
leechers: {$sum: '$torrent_leechers'}
}
}).exec(function (err, total) {
if (err) {
callback(err, null);
} else {
callback(null, total);
}
});
};
var countForumTopics = function (callback) {
Topic.count(function (err, count) {
if (err) {
callback(err, null);
} else {
callback(null, count);
}
});
};
var totalForumReplies = function (callback) {
Topic.aggregate({
$group: {
_id: null,
replies: {$sum: '$replyCount'}
}
}).exec(function (err, total) {
if (err) {
callback(err, null);
} else {
callback(null, total);
}
});
};
async.parallel([countUsers, countTorrents, totalTorrentsSize, totalUpDown, countForumTopics, totalForumReplies], function (err, results) {
if (err) {
return res.status(422).send(err);
} else {
res.json({
totalUsers: results[0],
totalTorrents: results[1],
totalTorrentsSize: results[2][0].size,
totalSeeders: results[2][0].seeders,
totalLeechers: results[2][0].leechers,
totalUploaded: results[3][0].uploaded,
totalDownloaded: results[3][0].downloaded,
totalForumTopics: results[4],
totalForumReplies: results[5][0].replies
});
}
});
};
/**
* Torrent middleware
*/

View File

@@ -39,7 +39,8 @@ exports.invokeRolesPolicies = function () {
{resources: '/api/my/seeding', permissions: '*'},
{resources: '/api/my/downloading', permissions: '*'},
{resources: '/api/:userId/seeding', permissions: '*'},
{resources: '/api/:userId/downloading', permissions: '*'}
{resources: '/api/:userId/downloading', permissions: '*'},
{resources: '/api/torrents/siteInfo', permissions: ['get']}
]
},
{
@@ -61,7 +62,8 @@ exports.invokeRolesPolicies = function () {
{resources: '/api/comments/:torrentId/:commentId/:subCommentId', permissions: ['put', 'delete']},
{resources: '/api/my/seeding', permissions: ['get']},
{resources: '/api/my/downloading', permissions: ['get']}
{resources: '/api/my/downloading', permissions: ['get']},
{resources: '/api/torrents/siteInfo', permissions: ['get']}
]
},
{
@@ -70,7 +72,8 @@ exports.invokeRolesPolicies = function () {
{resources: '/api/movieinfo/:tmdbid/:language', permissions: ['get']},
{resources: '/api/tvinfo/:tmdbid/:language', permissions: ['get']},
{resources: '/api/torrents', permissions: ['get']},
{resources: '/api/torrents/:torrentId', permissions: ['get']}
{resources: '/api/torrents/:torrentId', permissions: ['get']},
{resources: '/api/torrents/siteInfo', permissions: ['get']}
]
}
]

View File

@@ -8,7 +8,6 @@ var torrents = require('../controllers/torrents.server.controller'),
module.exports = function (app) {
// Articles collection routes
app.route('/api/movieinfo/:tmdbid/:language').all(torrentsPolicy.isAllowed)
.get(torrents.movieinfo);
@@ -28,6 +27,9 @@ module.exports = function (app) {
.get(torrents.list)
.post(torrents.create);
app.route('/api/torrents/siteInfo')
.get(torrents.siteInfo);
app.route('/api/torrents/:torrentId').all(torrentsPolicy.isAllowed)
.get(torrents.read)
.put(torrents.update)