fixed crash if empty topic was loaded without ajaxify

v1.18.x
Baris Soner Usakli 11 years ago
parent 84cbcc5a97
commit bbac361670

@ -182,7 +182,17 @@
return (n / 1000).toFixed(1) + 'k'; return (n / 1000).toFixed(1) + 'k';
} }
return n; 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();
} }
}; };

@ -189,7 +189,7 @@ var db = require('./database'),
if (parseInt(postData.deleted, 10) === 1) { if (parseInt(postData.deleted, 10) === 1) {
return callback(null); return callback(null);
} else { } else {
postData.relativeTime = new Date(parseInt(postData.timestamp || 0, 10)).toISOString(); postData.relativeTime = utils.toISOString(postData.timestamp);
next(null, postData); next(null, postData);
} }
}); });
@ -318,30 +318,28 @@ var db = require('./database'),
} }
db.getObjects(keys, function(err, data) { db.getObjects(keys, function(err, data) {
async.map(data, function(postData, _callback) { if(err) {
if (postData) { 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');
}
postTools.parse(postData.content, function(err, content) { async.map(data, function(postData, next) {
postData.content = content; if(!postData) {
_callback(null, postData); return next(null);
});
} else {
_callback(null);
} }
}, function(err, posts) {
if (!err) { postData.relativeTime = utils.toISOString(postData.timestamp);
return callback(null, posts); postData.relativeEditTime = parseInt(postData.edited, 10) !== 0 ? utils.toISOString(postData.edited) : '';
} else {
return callback(err, null); postTools.parse(postData.content, function(err, content) {
} if(err) {
}); return next(err);
}
postData.content = content;
next(null, postData);
});
}, callback);
}); });
} }

@ -532,9 +532,9 @@ var fs = require('fs'),
user.getUserData(uid, function (err, data) { user.getUserData(uid, function (err, data) {
if (data) { if (data) {
data.joindate = new Date(parseInt(data.joindate, 10)).toISOString(); data.joindate = utils.toISOString(data.joindate);
if(data.lastonline) { if(data.lastonline) {
data.lastonline = new Date(parseInt(data.lastonline, 10)).toISOString(); data.lastonline = utils.toISOString(data.lastonline);
} else { } else {
data.lastonline = data.joindate; 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) { ThreadTools.getLatestUndeletedPid = function(tid, callback) {
db.getSortedSetRevRange('tid:' + tid + ':posts', 0, -1, function(err, pids) { db.getSortedSetRevRange('tid:' + tid + ':posts', 0, -1, function(err, pids) {
if(err) { if(err) {

@ -211,7 +211,7 @@ var async = require('async'),
postData.favourited = false; postData.favourited = false;
postData.display_moderator_tools = true; postData.display_moderator_tools = true;
postData.relativeTime = new Date(postData.timestamp).toISOString(); postData.relativeTime = utils.toISOString(postData.timestamp);
callback(null, postData); callback(null, postData);
}); });
@ -314,9 +314,7 @@ var async = require('async'),
if(data) { if(data) {
data.title = validator.sanitize(data.title).escape(); data.title = validator.sanitize(data.title).escape();
if(data.timestamp) { data.relativeTime = utils.toISOString(data.timestamp);
data.relativeTime = new Date(parseInt(data.timestamp, 10)).toISOString();
}
} }
callback(null, data); callback(null, data);
@ -726,7 +724,7 @@ var async = require('async'),
topicData.teaser_userslug = topicInfo.teaserInfo.userslug || ''; topicData.teaser_userslug = topicInfo.teaserInfo.userslug || '';
topicData.teaser_userpicture = topicInfo.teaserInfo.picture || gravatar.url('', {}, https = nconf.get('https')); topicData.teaser_userpicture = topicInfo.teaserInfo.picture || gravatar.url('', {}, https = nconf.get('https'));
topicData.teaser_pid = topicInfo.teaserInfo.pid; 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)) { if (isTopicVisible(topicData, topicInfo)) {
retrieved_topics.push(topicData); retrieved_topics.push(topicData);
@ -775,8 +773,7 @@ var async = require('async'),
async.parallel([getTopicData, getTopicPosts, getPrivileges, getCategoryData], function(err, results) { async.parallel([getTopicData, getTopicPosts, getPrivileges, getCategoryData], function(err, results) {
if (err) { if (err) {
winston.error('[Topics.getTopicWithPosts] Could not retrieve topic data: ', err.message); winston.error('[Topics.getTopicWithPosts] Could not retrieve topic data: ', err.message);
callback(err, null); return callback(err, null);
return;
} }
var topicData = results[0], var topicData = results[0],
@ -791,6 +788,7 @@ var async = require('async'),
'locked': topicData.locked, 'locked': topicData.locked,
'deleted': topicData.deleted, 'deleted': topicData.deleted,
'pinned': topicData.pinned, 'pinned': topicData.pinned,
'timestamp': topicData.timestamp,
'slug': topicData.slug, 'slug': topicData.slug,
'postcount': topicData.postcount, 'postcount': topicData.postcount,
'viewcount': topicData.viewcount, 'viewcount': topicData.viewcount,
@ -844,7 +842,7 @@ var async = require('async'),
topicData.teaser_username = teaser.username || ''; topicData.teaser_username = teaser.username || '';
topicData.teaser_userslug = teaser.userslug || ''; topicData.teaser_userslug = teaser.userslug || '';
topicData.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; topicData.teaser_userpicture = teaser.picture;
callback(topicData); callback(topicData);

@ -1022,7 +1022,7 @@ var bcrypt = require('bcrypt'),
}).sort(function(a, b) { }).sort(function(a, b) {
return parseInt(b.datetime, 10) - parseInt(a.datetime, 10); return parseInt(b.datetime, 10) - parseInt(a.datetime, 10);
}).map(function(notif) { }).map(function(notif) {
notif.datetimeISO = new Date(parseInt(notif.datetime, 10)).toISOString(); notif.datetimeISO = utils.toISOString(notif.datetime);
notif.readClass = !notif.read ? 'unread' : ''; notif.readClass = !notif.read ? 'unread' : '';
return notif; return notif;

@ -536,10 +536,14 @@ if(nconf.get('ssl')) {
}); });
}, },
function (topicData, next) { function (topicData, next) {
var lastMod = 0,
var lastMod = topicData.timestamp,
sanitize = validator.sanitize, sanitize = validator.sanitize,
description = (function() { 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) { if (content.length > 255) {
content = content.substr(0, 255) + '...'; content = content.substr(0, 255) + '...';
@ -586,15 +590,15 @@ if(nconf.get('ssl')) {
}, },
{ {
property: 'og:image', property: 'og:image',
content: topicData.posts[0].picture content: topicData.posts.length?topicData.posts[0].picture:''
}, },
{ {
property: "article:published_time", property: "article:published_time",
content: new Date(parseInt(topicData.posts[0].timestamp, 10)).toISOString() content: utils.toISOString(topicData.timestamp)
}, },
{ {
property: 'article:modified_time', property: 'article:modified_time',
content: new Date(lastMod).toISOString() content: utils.toISOString(lastMod)
}, },
{ {
property: 'article:section', property: 'article:section',

Loading…
Cancel
Save