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.

29 lines
875 B
JavaScript

7 years ago
'use strict';
const nconf = require('nconf');
const validator = require('validator');
7 years ago
const helpers = require('./helpers');
const recentController = require('./recent');
7 years ago
const topController = module.exports;
7 years ago
topController.get = async function (req, res, next) {
const data = await recentController.getData(req, 'top', 'votes');
if (!data) {
return next();
}
const 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 + ']]';
}
7 years ago
const 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;
}
res.render('top', data);
7 years ago
};