You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
988 B
JavaScript

7 years ago
'use strict';
var async = require('async');
7 years ago
var nconf = require('nconf');
var validator = require('validator');
var helpers = require('./helpers');
7 years ago
var recentController = require('./recent');
7 years ago
var topController = module.exports;
topController.get = function (req, res, next) {
async.waterfall([
function (next) {
7 years ago
recentController.getData(req, 'top', 'votes', next);
7 years ago
},
7 years ago
function (data, next) {
if (!data) {
return next();
7 years ago
}
7 years ago
var term = helpers.terms[req.query.term] || 'alltime';
if (req.originalUrl.startsWith(nconf.get('relative_path') + '/api/top') || req.originalUrl.startsWith(nconf.get('relative_path') + '/top')) {
data.title = '[[pages:top-' + term + ']]';
}
var feedQs = data.rssFeedUrl.split('?')[1];
data.rssFeedUrl = nconf.get('relative_path') + '/top/' + (validator.escape(String(req.query.term)) || 'alltime') + '.rss';
if (req.loggedIn) {
data.rssFeedUrl += '?' + feedQs;
}
7 years ago
res.render('top', data);
},
], next);
};