mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 19:46:01 +01:00
crash fix
This commit is contained in:
@@ -70,7 +70,7 @@ topicsController.get = function(req, res, next) {
|
||||
function (topicData, next) {
|
||||
var description = '';
|
||||
|
||||
if(topicData.posts.length) {
|
||||
if (topicData.posts[0] && topicData.posts[0].content) {
|
||||
description = S(topicData.posts[0].content).stripTags().decodeHTMLEntities().s;
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ topicsController.get = function(req, res, next) {
|
||||
var ogImageUrl = '';
|
||||
if (topicData.thumb) {
|
||||
ogImageUrl = topicData.thumb;
|
||||
} else if(topicData.posts.length && topicData.posts[0].user && topicData.posts[0].user.picture){
|
||||
} else if(topicData.posts.length && topicData.posts[0] && topicData.posts[0].user && topicData.posts[0].user.picture){
|
||||
ogImageUrl = topicData.posts[0].user.picture;
|
||||
} else if(meta.config['brand:logo']) {
|
||||
ogImageUrl = meta.config['brand:logo'];
|
||||
|
||||
@@ -152,7 +152,7 @@ var async = require('async'),
|
||||
if (!data || !Array.isArray(data.posts)) {
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
data.posts = data.posts.filter(Boolean);
|
||||
callback(null, data.posts);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -44,7 +44,7 @@ module.exports = function(Topics) {
|
||||
Topics.addPostData = function(postData, uid, callback) {
|
||||
var pids = postData.map(function(post) {
|
||||
return post && post.pid;
|
||||
}).filter(Boolean);
|
||||
});
|
||||
|
||||
if (!Array.isArray(pids) || !pids.length) {
|
||||
return callback(null, []);
|
||||
@@ -61,7 +61,7 @@ module.exports = function(Topics) {
|
||||
var uids = [];
|
||||
|
||||
for(var i=0; i<postData.length; ++i) {
|
||||
if (uids.indexOf(postData[i].uid) === -1) {
|
||||
if (postData[i] && uids.indexOf(postData[i].uid) === -1) {
|
||||
uids.push(postData[i].uid);
|
||||
}
|
||||
}
|
||||
@@ -82,7 +82,7 @@ module.exports = function(Topics) {
|
||||
editors: function(next) {
|
||||
var editors = [];
|
||||
for(var i=0; i<postData.length; ++i) {
|
||||
if (postData[i].editor && editors.indexOf(postData[i].editor) === -1) {
|
||||
if (postData[i] && postData[i].editor && editors.indexOf(postData[i].editor) === -1) {
|
||||
editors.push(postData[i].editor);
|
||||
}
|
||||
}
|
||||
@@ -94,7 +94,7 @@ module.exports = function(Topics) {
|
||||
var editorData = {};
|
||||
editors.forEach(function(editor) {
|
||||
editorData[editor.uid] = editor;
|
||||
})
|
||||
});
|
||||
next(null, editorData);
|
||||
});
|
||||
},
|
||||
@@ -107,6 +107,7 @@ module.exports = function(Topics) {
|
||||
}
|
||||
|
||||
for (var i = 0; i < postData.length; ++i) {
|
||||
if (postData[i]) {
|
||||
postData[i].deleted = parseInt(postData[i].deleted, 10) === 1;
|
||||
postData[i].user = results.userData[postData[i].uid];
|
||||
postData[i].editor = postData[i].editor ? results.editors[postData[i].editor] : null;
|
||||
@@ -122,6 +123,7 @@ module.exports = function(Topics) {
|
||||
postData[i].content = '[[topic:post_is_deleted]]';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
callback(null, postData);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user