mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 03:26:04 +01:00
refactor abit adding error checking to missing parts
This commit is contained in:
17
src/posts.js
17
src/posts.js
@@ -131,17 +131,18 @@ var RDB = require('./redis.js'),
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: this function is never called except from some debug route. clean up?
|
|
||||||
Posts.getPostData = function(pid, callback) {
|
Posts.getPostData = function(pid, callback) {
|
||||||
RDB.hgetall('post:' + pid, function(err, data) {
|
RDB.hgetall('post:' + pid, function(err, data) {
|
||||||
if (err === null) {
|
if(err) {
|
||||||
plugins.fireHook('filter:post.get', data, function(err, newData) {
|
return callback(err, null);
|
||||||
if (!err) callback(newData);
|
|
||||||
else callback(data);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
winston.error(err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
plugins.fireHook('filter:post.get', data, function(err, newData) {
|
||||||
|
if(err) {
|
||||||
|
return callback(err, null);
|
||||||
|
}
|
||||||
|
callback(null, newData);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,50 +1,76 @@
|
|||||||
|
|
||||||
|
var user = require('./../user'),
|
||||||
|
categories = require('./../categories'),
|
||||||
|
topics = require('./../topics'),
|
||||||
|
posts = require('./../posts');
|
||||||
|
|
||||||
|
|
||||||
var DebugRoute = function(app) {
|
var DebugRoute = function(app) {
|
||||||
app.namespace('/debug', function() {
|
|
||||||
app.get('/cid/:cid', function (req, res) {
|
|
||||||
categories.getCategoryData(req.params.cid, function (err, data) {
|
|
||||||
if (data) {
|
|
||||||
res.send(data);
|
|
||||||
} else {
|
|
||||||
res.send(404, "Category doesn't exist!");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
app.get('/tid/:tid', function (req, res) {
|
app.namespace('/debug', function() {
|
||||||
topics.getTopicData(req.params.tid, function (data) {
|
|
||||||
if (data) {
|
|
||||||
res.send(data);
|
|
||||||
} else {
|
|
||||||
res.send(404, "Topic doesn't exist!");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
app.get('/pid/:pid', function (req, res) {
|
app.get('/uid/:uid', function (req, res) {
|
||||||
posts.getPostData(req.params.pid, function (data) {
|
|
||||||
if (data) {
|
|
||||||
res.send(data);
|
|
||||||
} else {
|
|
||||||
res.send(404, "Post doesn't exist!");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
app.get('/prune', function(req, res) {
|
if (!req.params.uid)
|
||||||
var Notifications = require('../notifications');
|
return res.redirect('/404');
|
||||||
|
|
||||||
Notifications.prune(new Date(), function() {
|
user.getUserData(req.params.uid, function (err, data) {
|
||||||
console.log('done');
|
if (data) {
|
||||||
});
|
res.send(data);
|
||||||
res.send();
|
} else {
|
||||||
});
|
res.json(404, {
|
||||||
|
error: "User doesn't exist!"
|
||||||
app.get('/uuidtest', function(req, res) {
|
});
|
||||||
var Utils = require('../../public/src/utils.js');
|
}
|
||||||
|
|
||||||
res.send(Utils.generateUUID());
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
|
||||||
|
|
||||||
|
app.get('/cid/:cid', function (req, res) {
|
||||||
|
categories.getCategoryData(req.params.cid, function (err, data) {
|
||||||
|
if (data) {
|
||||||
|
res.send(data);
|
||||||
|
} else {
|
||||||
|
res.send(404, "Category doesn't exist!");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get('/tid/:tid', function (req, res) {
|
||||||
|
topics.getTopicData(req.params.tid, function (err, data) {
|
||||||
|
if (data) {
|
||||||
|
res.send(data);
|
||||||
|
} else {
|
||||||
|
res.send(404, "Topic doesn't exist!");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get('/pid/:pid', function (req, res) {
|
||||||
|
posts.getPostData(req.params.pid, function (err, data) {
|
||||||
|
if (data) {
|
||||||
|
res.send(data);
|
||||||
|
} else {
|
||||||
|
res.send(404, "Post doesn't exist!");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get('/prune', function(req, res) {
|
||||||
|
var Notifications = require('../notifications');
|
||||||
|
|
||||||
|
Notifications.prune(new Date(), function() {
|
||||||
|
console.log('done');
|
||||||
|
});
|
||||||
|
res.send();
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get('/uuidtest', function(req, res) {
|
||||||
|
var Utils = require('../../public/src/utils.js');
|
||||||
|
|
||||||
|
res.send(Utils.generateUUID());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = DebugRoute;
|
module.exports = DebugRoute;
|
||||||
@@ -14,22 +14,6 @@ var user = require('./../user.js'),
|
|||||||
(function (User) {
|
(function (User) {
|
||||||
User.createRoutes = function (app) {
|
User.createRoutes = function (app) {
|
||||||
|
|
||||||
app.get('/uid/:uid', function (req, res) {
|
|
||||||
|
|
||||||
if (!req.params.uid)
|
|
||||||
return res.redirect('/404');
|
|
||||||
|
|
||||||
user.getUserData(req.params.uid, function (err, data) {
|
|
||||||
if (data) {
|
|
||||||
res.send(data);
|
|
||||||
} else {
|
|
||||||
res.json(404, {
|
|
||||||
error: "User doesn't exist!"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
app.namespace('/users', function () {
|
app.namespace('/users', function () {
|
||||||
app.get('', function (req, res) {
|
app.get('', function (req, res) {
|
||||||
app.build_header({
|
app.build_header({
|
||||||
|
|||||||
@@ -20,28 +20,36 @@ var RDB = require('./redis.js'),
|
|||||||
|
|
||||||
Topics.getTopicData = function(tid, callback) {
|
Topics.getTopicData = function(tid, callback) {
|
||||||
RDB.hgetall('topic:' + tid, function(err, data) {
|
RDB.hgetall('topic:' + tid, function(err, data) {
|
||||||
if (err === null) {
|
if(err) {
|
||||||
if(data) {
|
return callback(err, null);
|
||||||
data.title = validator.sanitize(data.title).escape();
|
|
||||||
if(data.timestamp) {
|
|
||||||
data.relativeTime = new Date(parseInt(data.timestamp, 10)).toISOString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
callback(data);
|
|
||||||
} else {
|
|
||||||
console.log(err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(data) {
|
||||||
|
data.title = validator.sanitize(data.title).escape();
|
||||||
|
if(data.timestamp) {
|
||||||
|
data.relativeTime = new Date(parseInt(data.timestamp, 10)).toISOString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(null, data);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Topics.getTopicDataWithUser = function(tid, callback) {
|
Topics.getTopicDataWithUser = function(tid, callback) {
|
||||||
Topics.getTopicData(tid, function(topic) {
|
Topics.getTopicData(tid, function(err, topic) {
|
||||||
|
if(err) {
|
||||||
|
return callback(err, null);
|
||||||
|
}
|
||||||
|
|
||||||
user.getUserFields(topic.uid, ['username', 'userslug', 'picture'] , function(err, userData) {
|
user.getUserFields(topic.uid, ['username', 'userslug', 'picture'] , function(err, userData) {
|
||||||
|
if(err) {
|
||||||
|
return callback(err, null);
|
||||||
|
}
|
||||||
|
|
||||||
topic.username = userData.username;
|
topic.username = userData.username;
|
||||||
topic.userslug = userData.userslug
|
topic.userslug = userData.userslug
|
||||||
topic.picture = userData.picture;
|
topic.picture = userData.picture;
|
||||||
callback(topic);
|
callback(null, topic);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -331,7 +339,7 @@ var RDB = require('./redis.js'),
|
|||||||
}
|
}
|
||||||
|
|
||||||
function loadTopic(tid, callback) {
|
function loadTopic(tid, callback) {
|
||||||
Topics.getTopicData(tid, function(topicData) {
|
Topics.getTopicData(tid, function(err, topicData) {
|
||||||
if (!topicData) {
|
if (!topicData) {
|
||||||
return callback(null);
|
return callback(null);
|
||||||
}
|
}
|
||||||
@@ -381,9 +389,7 @@ var RDB = require('./redis.js'),
|
|||||||
Topics.increaseViewCount(tid);
|
Topics.increaseViewCount(tid);
|
||||||
|
|
||||||
function getTopicData(next) {
|
function getTopicData(next) {
|
||||||
Topics.getTopicData(tid, function(topicData) {
|
Topics.getTopicData(tid, next);
|
||||||
next(null, topicData);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTopicPosts(next) {
|
function getTopicPosts(next) {
|
||||||
@@ -442,9 +448,7 @@ var RDB = require('./redis.js'),
|
|||||||
Topics.getTopicForCategoryView = function(tid, uid, callback) {
|
Topics.getTopicForCategoryView = function(tid, uid, callback) {
|
||||||
|
|
||||||
function getTopicData(next) {
|
function getTopicData(next) {
|
||||||
Topics.getTopicDataWithUser(tid, function(topic) {
|
Topics.getTopicDataWithUser(tid, next);
|
||||||
next(null, topic);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getReadStatus(next) {
|
function getReadStatus(next) {
|
||||||
@@ -517,7 +521,7 @@ var RDB = require('./redis.js'),
|
|||||||
});
|
});
|
||||||
|
|
||||||
async.each(tids, function(tid, next) {
|
async.each(tids, function(tid, next) {
|
||||||
Topics.getTopicDataWithUser(tid, function(topicData) {
|
Topics.getTopicDataWithUser(tid, function(err, topicData) {
|
||||||
topics.push(topicData);
|
topics.push(topicData);
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -688,7 +688,7 @@ module.exports.init = function(io) {
|
|||||||
socket.on('api:composer.push', function(data) {
|
socket.on('api:composer.push', function(data) {
|
||||||
if (uid > 0 || meta.config.allowGuestPosting === '1') {
|
if (uid > 0 || meta.config.allowGuestPosting === '1') {
|
||||||
if (parseInt(data.tid) > 0) {
|
if (parseInt(data.tid) > 0) {
|
||||||
topics.getTopicData(data.tid, function(topicData) {
|
topics.getTopicData(data.tid, function(err, topicData) {
|
||||||
if (data.body)
|
if (data.body)
|
||||||
topicData.body = data.body;
|
topicData.body = data.body;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user