diff --git a/src/controllers/admin/appearance.js b/src/controllers/admin/appearance.js index 021733d417..65256f62ad 100644 --- a/src/controllers/admin/appearance.js +++ b/src/controllers/admin/appearance.js @@ -1,12 +1,9 @@ 'use strict'; -var appearanceController = {}; +var appearanceController = module.exports; appearanceController.get = function (req, res) { var term = req.params.term ? req.params.term : 'themes'; res.render('admin/appearance/' + term, {}); }; - - -module.exports = appearanceController; diff --git a/src/controllers/admin/cache.js b/src/controllers/admin/cache.js index dea5f0345b..1284be08be 100644 --- a/src/controllers/admin/cache.js +++ b/src/controllers/admin/cache.js @@ -1,6 +1,6 @@ 'use strict'; -var cacheController = {}; +var cacheController = module.exports; cacheController.get = function (req, res) { var postCache = require('../../posts/cache'); @@ -37,6 +37,3 @@ cacheController.get = function (req, res) { }, }); }; - - -module.exports = cacheController; diff --git a/src/controllers/admin/dashboard.js b/src/controllers/admin/dashboard.js index 70149e580e..8b1751d2a6 100644 --- a/src/controllers/admin/dashboard.js +++ b/src/controllers/admin/dashboard.js @@ -7,76 +7,79 @@ var db = require('../../database'); var meta = require('../../meta'); var plugins = require('../../plugins'); -var dashboardController = {}; - +var dashboardController = module.exports; dashboardController.get = function (req, res, next) { - async.parallel({ - stats: function (next) { - getStats(next); - }, - notices: function (next) { - var notices = [ - { - done: !meta.reloadRequired, - doneText: '[[admin/general/dashboard:restart-not-required]]', - notDoneText: '[[admin/general/dashboard:restart-required]]', - }, - { - done: plugins.hasListeners('filter:search.query'), - doneText: '[[admin/general/dashboard:search-plugin-installed]]', - notDoneText: '[[admin/general/dashboard:search-plugin-not-installed]]', - tooltip: '[[admin/general/dashboard:search-plugin-tooltip]]', - link: '/admin/extend/plugins', + async.waterfall([ + function (next) { + async.parallel({ + stats: function (next) { + getStats(next); }, - ]; + notices: function (next) { + var notices = [ + { + done: !meta.reloadRequired, + doneText: '[[admin/general/dashboard:restart-not-required]]', + notDoneText: '[[admin/general/dashboard:restart-required]]', + }, + { + done: plugins.hasListeners('filter:search.query'), + doneText: '[[admin/general/dashboard:search-plugin-installed]]', + notDoneText: '[[admin/general/dashboard:search-plugin-not-installed]]', + tooltip: '[[admin/general/dashboard:search-plugin-tooltip]]', + link: '/admin/extend/plugins', + }, + ]; - if (global.env !== 'production') { - notices.push({ - done: false, - notDoneText: '[[admin/general/dashboard:running-in-development]]', - }); - } + if (global.env !== 'production') { + notices.push({ + done: false, + notDoneText: '[[admin/general/dashboard:running-in-development]]', + }); + } - plugins.fireHook('filter:admin.notices', notices, next); + plugins.fireHook('filter:admin.notices', notices, next); + }, + }, next); }, - }, function (err, results) { - if (err) { - return next(err); - } - res.render('admin/general/dashboard', { - version: nconf.get('version'), - notices: results.notices, - stats: results.stats, - }); - }); + function (results) { + res.render('admin/general/dashboard', { + version: nconf.get('version'), + notices: results.notices, + stats: results.stats, + }); + }, + ], next); }; function getStats(callback) { - async.parallel([ + async.waterfall([ function (next) { - getStatsForSet('ip:recent', 'uniqueIPCount', next); - }, - function (next) { - getStatsForSet('users:joindate', 'userCount', next); - }, - function (next) { - getStatsForSet('posts:pid', 'postCount', next); - }, - function (next) { - getStatsForSet('topics:tid', 'topicCount', next); + async.parallel([ + function (next) { + getStatsForSet('ip:recent', 'uniqueIPCount', next); + }, + function (next) { + getStatsForSet('users:joindate', 'userCount', next); + }, + function (next) { + getStatsForSet('posts:pid', 'postCount', next); + }, + function (next) { + getStatsForSet('topics:tid', 'topicCount', next); + }, + ], next); }, - ], function (err, results) { - if (err) { - return callback(err); - } - results[0].name = '[[admin/general/dashboard:unique-visitors]]'; - results[1].name = '[[admin/general/dashboard:users]]'; - results[2].name = '[[admin/general/dashboard:posts]]'; - results[3].name = '[[admin/general/dashboard:topics]]'; + function (results, next) { + results[0].name = '[[admin/general/dashboard:unique-visitors]]'; + results[1].name = '[[admin/general/dashboard:users]]'; + results[2].name = '[[admin/general/dashboard:posts]]'; + results[3].name = '[[admin/general/dashboard:topics]]'; - callback(null, results); - }); + next(null, results); + }, + ], callback); } function getStatsForSet(set, field, callback) { @@ -108,5 +111,3 @@ function getGlobalField(field, callback) { callback(err, parseInt(count, 10) || 0); }); } - -module.exports = dashboardController; diff --git a/src/controllers/admin/database.js b/src/controllers/admin/database.js index 9ce8a3c00f..efec771ee6 100644 --- a/src/controllers/admin/database.js +++ b/src/controllers/admin/database.js @@ -3,33 +3,32 @@ var async = require('async'); var nconf = require('nconf'); -var databaseController = {}; - +var databaseController = module.exports; databaseController.get = function (req, res, next) { - async.parallel({ - redis: function (next) { - if (nconf.get('redis')) { - var rdb = require('../../database/redis'); - rdb.info(rdb.client, next); - } else { - next(); - } + async.waterfall([ + function (next) { + async.parallel({ + redis: function (next) { + if (nconf.get('redis')) { + var rdb = require('../../database/redis'); + rdb.info(rdb.client, next); + } else { + next(); + } + }, + mongo: function (next) { + if (nconf.get('mongo')) { + var mdb = require('../../database/mongo'); + mdb.info(mdb.client, next); + } else { + next(); + } + }, + }, next); }, - mongo: function (next) { - if (nconf.get('mongo')) { - var mdb = require('../../database/mongo'); - mdb.info(mdb.client, next); - } else { - next(); - } + function (results) { + res.render('admin/advanced/database', results); }, - }, function (err, results) { - if (err) { - return next(err); - } - res.render('admin/advanced/database', results); - }); + ], next); }; - -module.exports = databaseController; diff --git a/src/controllers/admin/errors.js b/src/controllers/admin/errors.js index 5a00e95537..55f790edab 100644 --- a/src/controllers/admin/errors.js +++ b/src/controllers/admin/errors.js @@ -6,33 +6,28 @@ var json2csv = require('json-2-csv').json2csv; var meta = require('../../meta'); var analytics = require('../../analytics'); -var errorsController = {}; +var errorsController = module.exports; errorsController.get = function (req, res, next) { - async.parallel({ - 'not-found': async.apply(meta.errors.get, true), - analytics: async.apply(analytics.getErrorAnalytics), - }, function (err, data) { - if (err) { - return next(err); - } - - res.render('admin/advanced/errors', data); - }); + async.waterfall([ + function (next) { + async.parallel({ + 'not-found': async.apply(meta.errors.get, true), + analytics: async.apply(analytics.getErrorAnalytics), + }, next); + }, + function (data) { + res.render('admin/advanced/errors', data); + }, + ], next); }; errorsController.export = function (req, res, next) { async.waterfall([ async.apply(meta.errors.get, false), async.apply(json2csv), - ], function (err, csv) { - if (err) { - return next(err); - } - - res.set('Content-Type', 'text/csv').set('Content-Disposition', 'attachment; filename="404.csv"').send(csv); - }); + function (csv) { + res.set('Content-Type', 'text/csv').set('Content-Disposition', 'attachment; filename="404.csv"').send(csv); + }, + ], next); }; - - -module.exports = errorsController; diff --git a/src/controllers/admin/events.js b/src/controllers/admin/events.js index 97838d2266..f6988ef72e 100644 --- a/src/controllers/admin/events.js +++ b/src/controllers/admin/events.js @@ -6,8 +6,7 @@ var db = require('../../database'); var events = require('../../events'); var pagination = require('../../pagination'); -var eventsController = {}; - +var eventsController = module.exports; eventsController.get = function (req, res, next) { var page = parseInt(req.query.page, 10) || 1; @@ -15,27 +14,26 @@ eventsController.get = function (req, res, next) { var start = (page - 1) * itemsPerPage; var stop = start + itemsPerPage - 1; - async.parallel({ - eventCount: function (next) { - db.sortedSetCard('events:time', next); + async.waterfall([ + function (next) { + async.parallel({ + eventCount: function (next) { + db.sortedSetCard('events:time', next); + }, + events: function (next) { + events.getEvents(start, stop, next); + }, + }, next); }, - events: function (next) { - events.getEvents(start, stop, next); + function (results) { + var pageCount = Math.max(1, Math.ceil(results.eventCount / itemsPerPage)); + + res.render('admin/advanced/events', { + events: results.events, + pagination: pagination.create(page, pageCount), + next: 20, + }); }, - }, function (err, results) { - if (err) { - return next(err); - } - - var pageCount = Math.max(1, Math.ceil(results.eventCount / itemsPerPage)); - - res.render('admin/advanced/events', { - events: results.events, - pagination: pagination.create(page, pageCount), - next: 20, - }); - }); + ], next); }; - -module.exports = eventsController; diff --git a/src/controllers/admin/groups.js b/src/controllers/admin/groups.js index b15f7197d1..b8d9291474 100644 --- a/src/controllers/admin/groups.js +++ b/src/controllers/admin/groups.js @@ -7,7 +7,7 @@ var groups = require('../../groups'); var meta = require('../../meta'); var pagination = require('../../pagination'); -var groupsController = {}; +var groupsController = module.exports; groupsController.list = function (req, res, next) { var page = parseInt(req.query.page, 10) || 1; @@ -30,20 +30,14 @@ groupsController.list = function (req, res, next) { groupNames = groupNames.slice(start, stop + 1); groups.getGroupsData(groupNames, next); }, - function (groupData, next) { - next(null, { groups: groupData, pagination: pagination.create(page, pageCount) }); + function (groupData) { + res.render('admin/manage/groups', { + groups: groupData, + pagination: pagination.create(page, pageCount), + yourid: req.uid, + }); }, - ], function (err, data) { - if (err) { - return next(err); - } - - res.render('admin/manage/groups', { - groups: data.groups, - pagination: data.pagination, - yourid: req.uid, - }); - }); + ], next); }; groupsController.get = function (req, res, callback) { @@ -58,13 +52,12 @@ groupsController.get = function (req, res, callback) { } groups.get(groupName, { uid: req.uid, truncateUserList: true, userListCount: 20 }, next); }, - ], function (err, group) { - if (err) { - return callback(err); - } - group.isOwner = true; - res.render('admin/manage/group', { group: group, allowPrivateGroups: parseInt(meta.config.allowPrivateGroups, 10) === 1 }); - }); + function (group) { + group.isOwner = true; + res.render('admin/manage/group', { + group: group, + allowPrivateGroups: parseInt(meta.config.allowPrivateGroups, 10) === 1, + }); + }, + ], callback); }; - -module.exports = groupsController; diff --git a/src/controllers/admin/homepage.js b/src/controllers/admin/homepage.js index 1450283847..bc0971622f 100644 --- a/src/controllers/admin/homepage.js +++ b/src/controllers/admin/homepage.js @@ -7,8 +7,7 @@ var categories = require('../../categories'); var privileges = require('../../privileges'); var plugins = require('../../plugins'); -var homePageController = {}; - +var homePageController = module.exports; homePageController.get = function (req, res, next) { async.waterfall([ @@ -28,39 +27,29 @@ homePageController.get = function (req, res, next) { name: 'Category: ' + category.name, }; }); - next(null, categoryData); - }, - ], function (err, categoryData) { - if (err || !categoryData) { - categoryData = []; - } - - plugins.fireHook('filter:homepage.get', { routes: [ - { - route: 'categories', - name: 'Categories', - }, - { - route: 'recent', - name: 'Recent', - }, - { - route: 'popular', - name: 'Popular', - }, - ].concat(categoryData) }, function (err, data) { - if (err) { - return next(err); - } + plugins.fireHook('filter:homepage.get', { routes: [ + { + route: 'categories', + name: 'Categories', + }, + { + route: 'recent', + name: 'Recent', + }, + { + route: 'popular', + name: 'Popular', + }, + ].concat(categoryData) }, next); + }, + function (data) { data.routes.push({ route: '', name: 'Custom', }); res.render('admin/general/homepage', data); - }); - }); + }, + ], next); }; - -module.exports = homePageController; diff --git a/src/controllers/admin/languages.js b/src/controllers/admin/languages.js index e2d848ddae..987c1d70cc 100644 --- a/src/controllers/admin/languages.js +++ b/src/controllers/admin/languages.js @@ -1,26 +1,27 @@ 'use strict'; +var async = require('async'); + var languages = require('../../languages'); var meta = require('../../meta'); -var languagesController = {}; - +var languagesController = module.exports; languagesController.get = function (req, res, next) { - languages.list(function (err, languages) { - if (err) { - return next(err); - } - - languages.forEach(function (language) { - language.selected = language.code === (meta.config.defaultLang || 'en-GB'); - }); + async.waterfall([ + function (next) { + languages.list(next); + }, + function (languages) { + languages.forEach(function (language) { + language.selected = language.code === (meta.config.defaultLang || 'en-GB'); + }); - res.render('admin/general/languages', { - languages: languages, - autoDetectLang: parseInt(meta.config.autoDetectLang, 10) === 1, - }); - }); + res.render('admin/general/languages', { + languages: languages, + autoDetectLang: parseInt(meta.config.autoDetectLang, 10) === 1, + }); + }, + ], next); }; -module.exports = languagesController; diff --git a/src/controllers/admin/logger.js b/src/controllers/admin/logger.js index 0e8006bbeb..4d8991e88c 100644 --- a/src/controllers/admin/logger.js +++ b/src/controllers/admin/logger.js @@ -1,9 +1,7 @@ 'use strict'; -var loggerController = {}; +var loggerController = module.exports; loggerController.get = function (req, res) { res.render('admin/development/logger', {}); }; - -module.exports = loggerController; diff --git a/src/controllers/admin/logs.js b/src/controllers/admin/logs.js index c2c5166dd7..1765cfc352 100644 --- a/src/controllers/admin/logs.js +++ b/src/controllers/admin/logs.js @@ -1,21 +1,23 @@ 'use strict'; +var async = require('async'); var validator = require('validator'); -var meta = require('../../meta'); +var meta = require('../../meta'); -var logsController = {}; +var logsController = module.exports; logsController.get = function (req, res, next) { - meta.logs.get(function (err, logs) { - if (err) { - return next(err); - } - - res.render('admin/advanced/logs', { - data: validator.escape(logs), - }); - }); + async.waterfall([ + function (next) { + meta.logs.get(next); + }, + function (logs) { + res.render('admin/advanced/logs', { + data: validator.escape(logs), + }); + }, + ], next); }; diff --git a/src/controllers/admin/plugins.js b/src/controllers/admin/plugins.js index 4e8e1a415e..b04458edae 100644 --- a/src/controllers/admin/plugins.js +++ b/src/controllers/admin/plugins.js @@ -3,54 +3,54 @@ var async = require('async'); var plugins = require('../../plugins'); -var pluginsController = {}; +var pluginsController = module.exports; pluginsController.get = function (req, res, next) { - async.parallel({ - compatible: function (next) { - plugins.list(function (err, plugins) { - if (err || !Array.isArray(plugins)) { - plugins = []; - } + async.waterfall([ + function (next) { + async.parallel({ + compatible: function (next) { + plugins.list(function (err, plugins) { + if (err || !Array.isArray(plugins)) { + plugins = []; + } - next(null, plugins); - }); + next(null, plugins); + }); + }, + all: function (next) { + plugins.list(false, function (err, plugins) { + if (err || !Array.isArray(plugins)) { + plugins = []; + } + + next(null, plugins); + }); + }, + }, next); }, - all: function (next) { - plugins.list(false, function (err, plugins) { - if (err || !Array.isArray(plugins)) { - plugins = []; - } + function (payload) { + var compatiblePkgNames = payload.compatible.map(function (pkgData) { + return pkgData.name; + }); - next(null, plugins); + res.render('admin/extend/plugins', { + installed: payload.compatible.filter(function (plugin) { + return plugin.installed; + }), + upgradeCount: payload.compatible.reduce(function (count, current) { + if (current.installed && current.outdated) { + count += 1; + } + return count; + }, 0), + download: payload.compatible.filter(function (plugin) { + return !plugin.installed; + }), + incompatible: payload.all.filter(function (plugin) { + return compatiblePkgNames.indexOf(plugin.name) === -1; + }), }); }, - }, function (err, payload) { - if (err) { - return next(err); - } - var compatiblePkgNames = payload.compatible.map(function (pkgData) { - return pkgData.name; - }); - - res.render('admin/extend/plugins', { - installed: payload.compatible.filter(function (plugin) { - return plugin.installed; - }), - upgradeCount: payload.compatible.reduce(function (count, current) { - if (current.installed && current.outdated) { - count += 1; - } - return count; - }, 0), - download: payload.compatible.filter(function (plugin) { - return !plugin.installed; - }), - incompatible: payload.all.filter(function (plugin) { - return compatiblePkgNames.indexOf(plugin.name) === -1; - }), - }); - }); + ], next); }; - -module.exports = pluginsController; diff --git a/src/controllers/admin/rewards.js b/src/controllers/admin/rewards.js index 56c5ed3cd0..37b49929bb 100644 --- a/src/controllers/admin/rewards.js +++ b/src/controllers/admin/rewards.js @@ -1,15 +1,18 @@ 'use strict'; -var rewardsController = {}; +var async = require('async'); -rewardsController.get = function (req, res, next) { - require('../../rewards/admin').get(function (err, data) { - if (err) { - return next(err); - } +var rewardsController = module.exports; - res.render('admin/extend/rewards', data); - }); +rewardsController.get = function (req, res, next) { + async.waterfall([ + function (next) { + require('../../rewards/admin').get(next); + }, + function (data) { + res.render('admin/extend/rewards', data); + }, + ], next); }; diff --git a/src/controllers/admin/settings.js b/src/controllers/admin/settings.js index 7d1db3e73e..97d9b17262 100644 --- a/src/controllers/admin/settings.js +++ b/src/controllers/admin/settings.js @@ -36,32 +36,30 @@ function renderEmail(req, res, next) { async.map(emails, function (email, next) { var path = email.replace(emailsPath, '').substr(1).replace('.tpl', ''); - fs.readFile(email, function (err, original) { - if (err) { - return next(err); - } + async.waterfall([ + function (next) { + fs.readFile(email, next); + }, + function (original, next) { + var text = meta.config['email:custom:' + path] ? meta.config['email:custom:' + path] : original.toString(); - var text = meta.config['email:custom:' + path] ? meta.config['email:custom:' + path] : original.toString(); - - next(null, { - path: path, - fullpath: email, - text: text, - original: original.toString(), - }); - }); + next(null, { + path: path, + fullpath: email, + text: text, + original: original.toString(), + }); + }, + ], next); }, next); }, - ], function (err, emails) { - if (err) { - return next(err); - } - - res.render('admin/settings/email', { - emails: emails, - sendable: emails.filter(function (email) { - return email.path.indexOf('_plaintext') === -1 && email.path.indexOf('partials') === -1; - }), - }); - }); + function (emails) { + res.render('admin/settings/email', { + emails: emails, + sendable: emails.filter(function (email) { + return email.path.indexOf('_plaintext') === -1 && email.path.indexOf('partials') === -1; + }), + }); + }, + ], next); } diff --git a/src/controllers/admin/sounds.js b/src/controllers/admin/sounds.js index 164bf4a427..c0ad374a55 100644 --- a/src/controllers/admin/sounds.js +++ b/src/controllers/admin/sounds.js @@ -1,9 +1,11 @@ 'use strict'; +var async = require('async'); + var plugins = require('../../plugins'); var meta = require('../../meta'); -var soundsController = {}; +var soundsController = module.exports; soundsController.get = function (req, res, next) { var types = [ @@ -11,37 +13,36 @@ soundsController.get = function (req, res, next) { 'chat-incoming', 'chat-outgoing', ]; - meta.configs.getFields(types, function (err, settings) { - if (err) { - return next(err); - } - - settings = settings || {}; - - var output = {}; + async.waterfall([ + function (next) { + meta.configs.getFields(types, next); + }, + function (settings) { + settings = settings || {}; + + var output = {}; + + types.forEach(function (type) { + var soundpacks = plugins.soundpacks.map(function (pack) { + var sounds = Object.keys(pack.sounds).map(function (soundName) { + var value = pack.name + ' | ' + soundName; + return { + name: soundName, + value: value, + selected: value === settings[type], + }; + }); - types.forEach(function (type) { - var soundpacks = plugins.soundpacks.map(function (pack) { - var sounds = Object.keys(pack.sounds).map(function (soundName) { - var value = pack.name + ' | ' + soundName; return { - name: soundName, - value: value, - selected: value === settings[type], + name: pack.name, + sounds: sounds, }; }); - return { - name: pack.name, - sounds: sounds, - }; + output[type + '-sound'] = soundpacks; }); - output[type + '-sound'] = soundpacks; - }); - - res.render('admin/general/sounds', output); - }); + res.render('admin/general/sounds', output); + }, + ], next); }; - -module.exports = soundsController; diff --git a/src/controllers/admin/tags.js b/src/controllers/admin/tags.js index f586e5f70c..3fec3915ec 100644 --- a/src/controllers/admin/tags.js +++ b/src/controllers/admin/tags.js @@ -1,18 +1,18 @@ 'use strict'; +var async = require('async'); + var topics = require('../../topics'); -var tagsController = {}; +var tagsController = module.exports; tagsController.get = function (req, res, next) { - topics.getTags(0, 199, function (err, tags) { - if (err) { - return next(err); - } - - res.render('admin/manage/tags', { tags: tags }); - }); + async.waterfall([ + function (next) { + topics.getTags(0, 199, next); + }, + function (tags) { + res.render('admin/manage/tags', { tags: tags }); + }, + ], next); }; - - -module.exports = tagsController; diff --git a/src/controllers/admin/themes.js b/src/controllers/admin/themes.js index cd70522fc9..850feb201d 100644 --- a/src/controllers/admin/themes.js +++ b/src/controllers/admin/themes.js @@ -6,28 +6,23 @@ var async = require('async'); var file = require('../../file'); -var themesController = {}; +var themesController = module.exports; var defaultScreenshotPath = path.join(__dirname, '../../../public/images/themes/default.png'); themesController.get = function (req, res, next) { var themeDir = path.join(__dirname, '../../../node_modules', req.params.theme); var themeConfigPath = path.join(themeDir, 'theme.json'); - + var screenshotPath; async.waterfall([ function (next) { - file.exists(themeConfigPath, function (err, exists) { - if (err) { - return next(err); - } - if (!exists) { - return next(Error('invalid-data')); - } - - next(); - }); + file.exists(themeConfigPath, next); }, - function (next) { + function (exists, next) { + if (!exists) { + return next(Error('invalid-data')); + } + fs.readFile(themeConfigPath, next); }, function (themeConfig, next) { @@ -38,16 +33,13 @@ themesController.get = function (req, res, next) { next(e); } }, - function (screenshotPath, next) { - file.exists(screenshotPath, function (err, exists) { - if (err) { - return next(err); - } - - res.sendFile(exists ? screenshotPath : defaultScreenshotPath); - }); + function (_screenshotPath, next) { + screenshotPath = _screenshotPath; + file.exists(screenshotPath, next); + }, + function (exists) { + res.sendFile(exists ? screenshotPath : defaultScreenshotPath); }, ], next); }; -module.exports = themesController; diff --git a/src/controllers/admin/users.js b/src/controllers/admin/users.js index 7dd08994cc..d454b287a1 100644 --- a/src/controllers/admin/users.js +++ b/src/controllers/admin/users.js @@ -10,7 +10,7 @@ var pagination = require('../../pagination'); var events = require('../../events'); var plugins = require('../../plugins'); -var usersController = {}; +var usersController = module.exports; var userFields = ['uid', 'username', 'userslug', 'email', 'postcount', 'joindate', 'banned', 'reputation', 'picture', 'flags', 'lastonline', 'email:confirmed']; @@ -63,57 +63,59 @@ usersController.registrationQueue = function (req, res, next) { var stop = start + itemsPerPage - 1; var invitations; - async.parallel({ - registrationQueueCount: function (next) { - db.sortedSetCard('registration:queue', next); - }, - users: function (next) { - user.getRegistrationQueue(start, stop, next); - }, - customHeaders: function (next) { - plugins.fireHook('filter:admin.registrationQueue.customHeaders', { headers: [] }, next); - }, - invites: function (next) { - async.waterfall([ - function (next) { - user.getAllInvites(next); + async.waterfall([ + function (next) { + async.parallel({ + registrationQueueCount: function (next) { + db.sortedSetCard('registration:queue', next); }, - function (_invitations, next) { - invitations = _invitations; - async.map(invitations, function (invites, next) { - user.getUserField(invites.uid, 'username', next); - }, next); + users: function (next) { + user.getRegistrationQueue(start, stop, next); }, - function (usernames, next) { - invitations.forEach(function (invites, index) { - invites.username = usernames[index]; - }); - async.map(invitations, function (invites, next) { - async.map(invites.invitations, user.getUsernameByEmail, next); - }, next); + customHeaders: function (next) { + plugins.fireHook('filter:admin.registrationQueue.customHeaders', { headers: [] }, next); }, - function (usernames, next) { - invitations.forEach(function (invites, index) { - invites.invitations = invites.invitations.map(function (email, i) { - return { - email: email, - username: usernames[index][i] === '[[global:guest]]' ? '' : usernames[index][i], - }; - }); - }); - next(null, invitations); + invites: function (next) { + async.waterfall([ + function (next) { + user.getAllInvites(next); + }, + function (_invitations, next) { + invitations = _invitations; + async.map(invitations, function (invites, next) { + user.getUserField(invites.uid, 'username', next); + }, next); + }, + function (usernames, next) { + invitations.forEach(function (invites, index) { + invites.username = usernames[index]; + }); + async.map(invitations, function (invites, next) { + async.map(invites.invitations, user.getUsernameByEmail, next); + }, next); + }, + function (usernames, next) { + invitations.forEach(function (invites, index) { + invites.invitations = invites.invitations.map(function (email, i) { + return { + email: email, + username: usernames[index][i] === '[[global:guest]]' ? '' : usernames[index][i], + }; + }); + }); + next(null, invitations); + }, + ], next); }, - ], next); + }, next); }, - }, function (err, data) { - if (err) { - return next(err); - } - var pageCount = Math.max(1, Math.ceil(data.registrationQueueCount / itemsPerPage)); - data.pagination = pagination.create(page, pageCount); - data.customHeaders = data.customHeaders.headers; - res.render('admin/manage/registration', data); - }); + function (data) { + var pageCount = Math.max(1, Math.ceil(data.registrationQueueCount / itemsPerPage)); + data.pagination = pagination.create(page, pageCount); + data.customHeaders = data.customHeaders.headers; + res.render('admin/manage/registration', data); + }, + ], next); }; function getUsers(set, section, min, max, req, res, next) { @@ -123,47 +125,48 @@ function getUsers(set, section, min, max, req, res, next) { var stop = start + resultsPerPage - 1; var byScore = min !== undefined && max !== undefined; - async.parallel({ - count: function (next) { - if (byScore) { - db.sortedSetCount(set, min, max, next); - } else if (set === 'users:banned' || set === 'users:notvalidated') { - db.sortedSetCard(set, next); - } else { - db.getObjectField('global', 'userCount', next); - } - }, - users: function (next) { - async.waterfall([ - function (next) { + async.waterfall([ + function (next) { + async.parallel({ + count: function (next) { if (byScore) { - db.getSortedSetRevRangeByScore(set, start, resultsPerPage, max, min, next); + db.sortedSetCount(set, min, max, next); + } else if (set === 'users:banned' || set === 'users:notvalidated') { + db.sortedSetCard(set, next); } else { - user.getUidsFromSet(set, start, stop, next); + db.getObjectField('global', 'userCount', next); } }, - function (uids, next) { - user.getUsersWithFields(uids, userFields, req.uid, next); + users: function (next) { + async.waterfall([ + function (next) { + if (byScore) { + db.getSortedSetRevRangeByScore(set, start, resultsPerPage, max, min, next); + } else { + user.getUidsFromSet(set, start, stop, next); + } + }, + function (uids, next) { + user.getUsersWithFields(uids, userFields, req.uid, next); + }, + ], next); }, - ], next); + }, next); }, - }, function (err, results) { - if (err) { - return next(err); - } - - results.users = results.users.filter(function (user) { - user.email = validator.escape(String(user.email || '')); - return user && parseInt(user.uid, 10); - }); - var data = { - users: results.users, - page: page, - pageCount: Math.max(1, Math.ceil(results.count / resultsPerPage)), - }; - data[section] = true; - render(req, res, data); - }); + function (results) { + results.users = results.users.filter(function (user) { + user.email = validator.escape(String(user.email || '')); + return user && parseInt(user.uid, 10); + }); + var data = { + users: results.users, + page: page, + pageCount: Math.max(1, Math.ceil(results.count / resultsPerPage)), + }; + data[section] = true; + render(req, res, data); + }, + ], next); } function render(req, res, data) { @@ -185,15 +188,14 @@ usersController.getCSV = function (req, res, next) { uid: req.user.uid, ip: req.ip, }); - - user.getUsersCSV(function (err, data) { - if (err) { - return next(err); - } - res.attachment('users.csv'); - res.setHeader('Content-Type', 'text/csv'); - res.end(data); - }); + async.waterfall([ + function (next) { + user.getUsersCSV(next); + }, + function (data) { + res.attachment('users.csv'); + res.setHeader('Content-Type', 'text/csv'); + res.end(data); + }, + ], next); }; - -module.exports = usersController; diff --git a/src/controllers/admin/widgets.js b/src/controllers/admin/widgets.js index 889fa1dcc6..15e75a0f68 100644 --- a/src/controllers/admin/widgets.js +++ b/src/controllers/admin/widgets.js @@ -1,16 +1,16 @@ 'use strict'; -var widgetsController = {}; +var async = require('async'); -widgetsController.get = function (req, res, next) { - require('../../widgets/admin').get(function (err, data) { - if (err) { - return next(err); - } +var widgetsController = module.exports; - res.render('admin/extend/widgets', data); - }); +widgetsController.get = function (req, res, next) { + async.waterfall([ + function (next) { + require('../../widgets/admin').get(next); + }, + function (data) { + res.render('admin/extend/widgets', data); + }, + ], next); }; - - -module.exports = widgetsController; diff --git a/src/controllers/topics.js b/src/controllers/topics.js index a794d40c8a..d560fbcb2a 100644 --- a/src/controllers/topics.js +++ b/src/controllers/topics.js @@ -150,6 +150,9 @@ topicsController.get = function (req, res, callback) { if (req.uid) { topicData.rssFeedUrl += '?uid=' + req.uid + '&token=' + rssToken; } + + addTags(topicData, req, res); + topicData.postIndex = req.params.post_index; topicData.pagination = pagination.create(currentPage, pageCount, req.query); topicData.pagination.rel.forEach(function (rel) { @@ -163,8 +166,6 @@ topicsController.get = function (req, res, callback) { req.session.tids_viewed[tid] = Date.now(); } - addTags(topicData, req, res); - if (req.uid) { topics.markAsRead([tid], req.uid, function (err, markedRead) { if (err) {