feat: async refactor
parent
47e30a67be
commit
3a9d83a44b
@ -1,36 +1,30 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
var nconf = require('nconf');
|
||||
var validator = require('validator');
|
||||
const nconf = require('nconf');
|
||||
const validator = require('validator');
|
||||
|
||||
var helpers = require('./helpers');
|
||||
var recentController = require('./recent');
|
||||
const helpers = require('./helpers');
|
||||
const recentController = require('./recent');
|
||||
|
||||
var popularController = module.exports;
|
||||
const popularController = module.exports;
|
||||
|
||||
popularController.get = function (req, res, next) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
recentController.getData(req, 'popular', 'posts', next);
|
||||
},
|
||||
function (data, next) {
|
||||
popularController.get = async function (req, res, next) {
|
||||
const data = await recentController.getData(req, 'popular', 'posts');
|
||||
if (!data) {
|
||||
return next();
|
||||
}
|
||||
var term = helpers.terms[req.query.term] || 'alltime';
|
||||
const term = helpers.terms[req.query.term] || 'alltime';
|
||||
if (req.originalUrl.startsWith(nconf.get('relative_path') + '/api/popular') || req.originalUrl.startsWith(nconf.get('relative_path') + '/popular')) {
|
||||
data.title = '[[pages:popular-' + term + ']]';
|
||||
var breadcrumbs = [{ text: '[[global:header.popular]]' }];
|
||||
const breadcrumbs = [{ text: '[[global:header.popular]]' }];
|
||||
data.breadcrumbs = helpers.buildBreadcrumbs(breadcrumbs);
|
||||
}
|
||||
var feedQs = data.rssFeedUrl.split('?')[1];
|
||||
|
||||
const feedQs = data.rssFeedUrl.split('?')[1];
|
||||
data.rssFeedUrl = nconf.get('relative_path') + '/popular/' + (validator.escape(String(req.query.term)) || 'alltime') + '.rss';
|
||||
if (req.loggedIn) {
|
||||
data.rssFeedUrl += '?' + feedQs;
|
||||
}
|
||||
res.render('popular', data);
|
||||
},
|
||||
], next);
|
||||
};
|
||||
|
@ -1,35 +1,28 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
var nconf = require('nconf');
|
||||
var validator = require('validator');
|
||||
const nconf = require('nconf');
|
||||
const validator = require('validator');
|
||||
|
||||
var helpers = require('./helpers');
|
||||
var recentController = require('./recent');
|
||||
const helpers = require('./helpers');
|
||||
const recentController = require('./recent');
|
||||
|
||||
var topController = module.exports;
|
||||
const topController = module.exports;
|
||||
|
||||
topController.get = function (req, res, next) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
recentController.getData(req, 'top', 'votes', next);
|
||||
},
|
||||
function (data, next) {
|
||||
topController.get = async function (req, res, next) {
|
||||
const data = await recentController.getData(req, 'top', 'votes');
|
||||
if (!data) {
|
||||
return next();
|
||||
}
|
||||
var term = helpers.terms[req.query.term] || 'alltime';
|
||||
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 + ']]';
|
||||
}
|
||||
|
||||
var feedQs = data.rssFeedUrl.split('?')[1];
|
||||
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);
|
||||
},
|
||||
], next);
|
||||
};
|
||||
|
Loading…
Reference in New Issue