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