mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 19:46:01 +01:00
fixed crash if empty topic was loaded without ajaxify
This commit is contained in:
@@ -182,7 +182,17 @@
|
||||
return (n / 1000).toFixed(1) + 'k';
|
||||
}
|
||||
return n;
|
||||
},
|
||||
|
||||
toISOString: function(timestamp) {
|
||||
try {
|
||||
return new Date(parseInt(timestamp, 10)).toISOString();
|
||||
} catch(e){
|
||||
console.log(e.message);
|
||||
}
|
||||
return new Date(parseInt(0, 10)).toISOString();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
42
src/posts.js
42
src/posts.js
@@ -189,7 +189,7 @@ var db = require('./database'),
|
||||
if (parseInt(postData.deleted, 10) === 1) {
|
||||
return callback(null);
|
||||
} else {
|
||||
postData.relativeTime = new Date(parseInt(postData.timestamp || 0, 10)).toISOString();
|
||||
postData.relativeTime = utils.toISOString(postData.timestamp);
|
||||
next(null, postData);
|
||||
}
|
||||
});
|
||||
@@ -318,30 +318,28 @@ var db = require('./database'),
|
||||
}
|
||||
|
||||
db.getObjects(keys, function(err, data) {
|
||||
async.map(data, function(postData, _callback) {
|
||||
if (postData) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
try {
|
||||
postData.relativeTime = new Date(parseInt(postData.timestamp,10)).toISOString();
|
||||
postData.relativeEditTime = parseInt(postData.edited, 10) !== 0 ? (new Date(parseInt(postData.edited, 10)).toISOString()) : '';
|
||||
} catch(e) {
|
||||
require('winston').err('invalid time value');
|
||||
async.map(data, function(postData, next) {
|
||||
if(!postData) {
|
||||
return next(null);
|
||||
}
|
||||
|
||||
postData.relativeTime = utils.toISOString(postData.timestamp);
|
||||
postData.relativeEditTime = parseInt(postData.edited, 10) !== 0 ? utils.toISOString(postData.edited) : '';
|
||||
|
||||
postTools.parse(postData.content, function(err, content) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
postTools.parse(postData.content, function(err, content) {
|
||||
postData.content = content;
|
||||
_callback(null, postData);
|
||||
});
|
||||
} else {
|
||||
_callback(null);
|
||||
}
|
||||
}, function(err, posts) {
|
||||
if (!err) {
|
||||
return callback(null, posts);
|
||||
} else {
|
||||
return callback(err, null);
|
||||
}
|
||||
});
|
||||
postData.content = content;
|
||||
next(null, postData);
|
||||
});
|
||||
|
||||
}, callback);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -532,9 +532,9 @@ var fs = require('fs'),
|
||||
|
||||
user.getUserData(uid, function (err, data) {
|
||||
if (data) {
|
||||
data.joindate = new Date(parseInt(data.joindate, 10)).toISOString();
|
||||
data.joindate = utils.toISOString(data.joindate);
|
||||
if(data.lastonline) {
|
||||
data.lastonline = new Date(parseInt(data.lastonline, 10)).toISOString();
|
||||
data.lastonline = utils.toISOString(data.lastonline);
|
||||
} else {
|
||||
data.lastonline = data.joindate;
|
||||
}
|
||||
|
||||
@@ -259,6 +259,16 @@ var winston = require('winston'),
|
||||
});
|
||||
}
|
||||
|
||||
ThreadTools.getLatestUndeletedPost = function(tid, callback) {
|
||||
ThreadTools.getLatestUndeletedPid(tid, function(err, pid) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
posts.getPostData(pid, callback);
|
||||
});
|
||||
}
|
||||
|
||||
ThreadTools.getLatestUndeletedPid = function(tid, callback) {
|
||||
db.getSortedSetRevRange('tid:' + tid + ':posts', 0, -1, function(err, pids) {
|
||||
if(err) {
|
||||
|
||||
@@ -211,7 +211,7 @@ var async = require('async'),
|
||||
|
||||
postData.favourited = false;
|
||||
postData.display_moderator_tools = true;
|
||||
postData.relativeTime = new Date(postData.timestamp).toISOString();
|
||||
postData.relativeTime = utils.toISOString(postData.timestamp);
|
||||
|
||||
callback(null, postData);
|
||||
});
|
||||
@@ -314,9 +314,7 @@ var async = require('async'),
|
||||
|
||||
if(data) {
|
||||
data.title = validator.sanitize(data.title).escape();
|
||||
if(data.timestamp) {
|
||||
data.relativeTime = new Date(parseInt(data.timestamp, 10)).toISOString();
|
||||
}
|
||||
data.relativeTime = utils.toISOString(data.timestamp);
|
||||
}
|
||||
|
||||
callback(null, data);
|
||||
@@ -726,7 +724,7 @@ var async = require('async'),
|
||||
topicData.teaser_userslug = topicInfo.teaserInfo.userslug || '';
|
||||
topicData.teaser_userpicture = topicInfo.teaserInfo.picture || gravatar.url('', {}, https = nconf.get('https'));
|
||||
topicData.teaser_pid = topicInfo.teaserInfo.pid;
|
||||
topicData.teaser_timestamp = topicInfo.teaserInfo.timestamp ? (new Date(parseInt(topicInfo.teaserInfo.timestamp, 10)).toISOString()) : '';
|
||||
topicData.teaser_timestamp = utils.toISOString(topicInfo.teaserInfo.timestamp);
|
||||
|
||||
if (isTopicVisible(topicData, topicInfo)) {
|
||||
retrieved_topics.push(topicData);
|
||||
@@ -775,8 +773,7 @@ var async = require('async'),
|
||||
async.parallel([getTopicData, getTopicPosts, getPrivileges, getCategoryData], function(err, results) {
|
||||
if (err) {
|
||||
winston.error('[Topics.getTopicWithPosts] Could not retrieve topic data: ', err.message);
|
||||
callback(err, null);
|
||||
return;
|
||||
return callback(err, null);
|
||||
}
|
||||
|
||||
var topicData = results[0],
|
||||
@@ -791,6 +788,7 @@ var async = require('async'),
|
||||
'locked': topicData.locked,
|
||||
'deleted': topicData.deleted,
|
||||
'pinned': topicData.pinned,
|
||||
'timestamp': topicData.timestamp,
|
||||
'slug': topicData.slug,
|
||||
'postcount': topicData.postcount,
|
||||
'viewcount': topicData.viewcount,
|
||||
@@ -844,7 +842,7 @@ var async = require('async'),
|
||||
topicData.teaser_username = teaser.username || '';
|
||||
topicData.teaser_userslug = teaser.userslug || '';
|
||||
topicData.userslug = teaser.userslug || '';
|
||||
topicData.teaser_timestamp = teaser.timestamp ? (new Date(parseInt(teaser.timestamp,10)).toISOString()) : '';
|
||||
topicData.teaser_timestamp = utils.toISOString(teaser.timestamp);
|
||||
topicData.teaser_userpicture = teaser.picture;
|
||||
|
||||
callback(topicData);
|
||||
|
||||
@@ -1022,7 +1022,7 @@ var bcrypt = require('bcrypt'),
|
||||
}).sort(function(a, b) {
|
||||
return parseInt(b.datetime, 10) - parseInt(a.datetime, 10);
|
||||
}).map(function(notif) {
|
||||
notif.datetimeISO = new Date(parseInt(notif.datetime, 10)).toISOString();
|
||||
notif.datetimeISO = utils.toISOString(notif.datetime);
|
||||
notif.readClass = !notif.read ? 'unread' : '';
|
||||
|
||||
return notif;
|
||||
|
||||
@@ -536,10 +536,14 @@ if(nconf.get('ssl')) {
|
||||
});
|
||||
},
|
||||
function (topicData, next) {
|
||||
var lastMod = 0,
|
||||
|
||||
var lastMod = topicData.timestamp,
|
||||
sanitize = validator.sanitize,
|
||||
description = (function() {
|
||||
var content = S(topicData.posts[0].content).stripTags().s;
|
||||
var content = '';
|
||||
if(topicData.posts.length) {
|
||||
content = S(topicData.posts[0].content).stripTags().s;
|
||||
}
|
||||
|
||||
if (content.length > 255) {
|
||||
content = content.substr(0, 255) + '...';
|
||||
@@ -586,15 +590,15 @@ if(nconf.get('ssl')) {
|
||||
},
|
||||
{
|
||||
property: 'og:image',
|
||||
content: topicData.posts[0].picture
|
||||
content: topicData.posts.length?topicData.posts[0].picture:''
|
||||
},
|
||||
{
|
||||
property: "article:published_time",
|
||||
content: new Date(parseInt(topicData.posts[0].timestamp, 10)).toISOString()
|
||||
content: utils.toISOString(topicData.timestamp)
|
||||
},
|
||||
{
|
||||
property: 'article:modified_time',
|
||||
content: new Date(lastMod).toISOString()
|
||||
content: utils.toISOString(lastMod)
|
||||
},
|
||||
{
|
||||
property: 'article:section',
|
||||
|
||||
Reference in New Issue
Block a user