From 1abfe5de634ba52ac8fbd1aed64af595c124cb0f Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Thu, 12 Dec 2013 12:17:58 -0500 Subject: [PATCH 1/4] added err to addUserInfoToPost --- src/posts.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/posts.js b/src/posts.js index fd250d5b38..dcb53d6379 100644 --- a/src/posts.js +++ b/src/posts.js @@ -14,7 +14,8 @@ var db = require('./database'), async = require('async'), nconf = require('nconf'), validator = require('validator'), - winston = require('winston'); + winston = require('winston'), + gravatar = require('gravatar'); (function(Posts) { var customUserInfo = {}; @@ -202,12 +203,16 @@ var db = require('./database'), } postTools.parseSignature(userData.signature, function(err, signature) { + if(err) { + return callback(err); + } + post.username = userData.username || 'anonymous'; post.userslug = userData.userslug || ''; post.user_rep = userData.reputation || 0; post.user_postcount = userData.postcount || 0; post.user_banned = parseInt(userData.banned, 10) === 1; - post.picture = userData.picture || require('gravatar').url('', {}, https = nconf.get('https')); + post.picture = userData.picture || gravatar.url('', {}, https = nconf.get('https')); post.signature = signature; for (var info in customUserInfo) { @@ -217,11 +222,16 @@ var db = require('./database'), } plugins.fireHook('filter:posts.custom_profile_info', {profile: "", uid: post.uid, pid: post.pid}, function(err, profile_info) { + if(err) { + return callback(err); + } post.additional_profile_info = profile_info.profile; if (post.editor !== '') { user.getUserFields(post.editor, ['username', 'userslug'], function(err, editorData) { - if (err) return callback(); + if (err) { + return callback(); + } post.editorname = editorData.username; post.editorslug = editorData.userslug; From 885242018f8ddb66c0a9a73b70437aeb7171cef6 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Thu, 12 Dec 2013 12:19:03 -0500 Subject: [PATCH 2/4] one more --- src/posts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/posts.js b/src/posts.js index dcb53d6379..6beabd964f 100644 --- a/src/posts.js +++ b/src/posts.js @@ -230,7 +230,7 @@ var db = require('./database'), if (post.editor !== '') { user.getUserFields(post.editor, ['username', 'userslug'], function(err, editorData) { if (err) { - return callback(); + return callback(err); } post.editorname = editorData.username; From cf8f0ca2252bf4d3ddc9441355debf766989a1aa Mon Sep 17 00:00:00 2001 From: psychobunny Date: Thu, 12 Dec 2013 16:02:12 -0500 Subject: [PATCH 3/4] cleanup --- src/routes/api.js | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/src/routes/api.js b/src/routes/api.js index ca0955ccbe..68ee19967f 100644 --- a/src/routes/api.js +++ b/src/routes/api.js @@ -39,29 +39,22 @@ var path = require('path'), res.json(200, config); }); - app.get('/home', function (req, res, next) { + app.get('/home', function (req, res) { var uid = (req.user) ? req.user.uid : 0; categories.getAllCategories(uid, function (err, data) { data.categories = data.categories.filter(function (category) { return (!category.disabled || parseInt(category.disabled, 10) === 0); }); - function getRecentReplies(category, callback) { - categories.getRecentReplies(category.cid, 2, function (err, posts) { - if(err) { - return callback(err); - } + function iterator(category, callback) { + categories.getRecentReplies(category.cid, 2, function (posts) { category.posts = posts; category.post_count = posts.length > 2 ? 2 : posts.length; callback(null); }); } - async.each(data.categories, getRecentReplies, function (err) { - if(err) { - return next(err); - } - + async.each(data.categories, iterator, function (err) { data.motd_class = (parseInt(meta.config.show_motd, 10) === 1 || meta.config.show_motd === undefined) ? '' : ' none'; data.motd_class += (meta.config.motd && meta.config.motd.length > 0 ? '' : ' default'); @@ -244,10 +237,6 @@ var path = require('path'), return callback(err, null); } - if(pids.length > 50) { - pids = pids.splice(0, 50); - } - posts.getPostSummaryByPids(pids, false, function (err, posts) { if (err){ return callback(err, null); @@ -263,10 +252,6 @@ var path = require('path'), return callback(err, null); } - if(tids.length > 50) { - tids = tids.splice(0, 50); - } - topics.getTopicsByTids(tids, 0, function (topics) { callback(null, topics); }, 0); @@ -313,7 +298,7 @@ var path = require('path'), app.get('/500', function(req, res) { res.json({errorMessage: 'testing'}); - }) + }); }); } }(exports)); \ No newline at end of file From 4397da144ff8a8463e6ee66c9b2006bc4036049d Mon Sep 17 00:00:00 2001 From: psychobunny Date: Thu, 12 Dec 2013 16:07:15 -0500 Subject: [PATCH 4/4] fixes crash introduced @1021615848e49da3434f00cfdb6fb79ab5990b47 --- src/routes/api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/api.js b/src/routes/api.js index 68ee19967f..0635188db3 100644 --- a/src/routes/api.js +++ b/src/routes/api.js @@ -47,7 +47,7 @@ var path = require('path'), }); function iterator(category, callback) { - categories.getRecentReplies(category.cid, 2, function (posts) { + categories.getRecentReplies(category.cid, 2, function (err, posts) { category.posts = posts; category.post_count = posts.length > 2 ? 2 : posts.length; callback(null);