mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
changed fireHook to be error-first, closes #319
This commit is contained in:
@@ -162,7 +162,7 @@ var fs = require('fs'),
|
||||
}
|
||||
}
|
||||
|
||||
callback(returnVal);
|
||||
callback(err, returnVal);
|
||||
});
|
||||
break;
|
||||
case 'action':
|
||||
@@ -185,7 +185,7 @@ var fs = require('fs'),
|
||||
} else {
|
||||
// Otherwise, this hook contains no methods
|
||||
var returnVal = (Array.isArray(args) ? args[0] : args);
|
||||
if (callback) callback(returnVal);
|
||||
if (callback) callback(err, returnVal);
|
||||
}
|
||||
},
|
||||
isActive: function(id, callback) {
|
||||
|
||||
@@ -102,8 +102,8 @@ var RDB = require('./redis.js'),
|
||||
|
||||
PostTools.privileges(pid, uid, function(privileges) {
|
||||
if (privileges.editable) {
|
||||
plugins.fireHook('filter:post.save', content, function(parsedContent) {
|
||||
content = parsedContent;
|
||||
plugins.fireHook('filter:post.save', content, function(err, parsedContent) {
|
||||
if (!err) content = parsedContent;
|
||||
success();
|
||||
});
|
||||
}
|
||||
@@ -193,8 +193,8 @@ var RDB = require('./redis.js'),
|
||||
PostTools.parse = function(raw, callback) {
|
||||
raw = raw || '';
|
||||
|
||||
plugins.fireHook('filter:post.parse', raw, function(parsed) {
|
||||
callback(null, parsed);
|
||||
plugins.fireHook('filter:post.parse', raw, function(err, parsed) {
|
||||
callback(null, !err ? parsed : raw);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
13
src/posts.js
13
src/posts.js
@@ -122,8 +122,9 @@ var RDB = require('./redis.js'),
|
||||
Posts.getPostData = function(pid, callback) {
|
||||
RDB.hgetall('post:' + pid, function(err, data) {
|
||||
if (err === null) {
|
||||
plugins.fireHook('filter:post.get', data, function(data) {
|
||||
callback(data);
|
||||
plugins.fireHook('filter:post.get', data, function(err, newData) {
|
||||
if (!err) callback(newData);
|
||||
else callback(data);
|
||||
});
|
||||
} else
|
||||
console.log(err);
|
||||
@@ -287,7 +288,9 @@ var RDB = require('./redis.js'),
|
||||
RDB.incr('global:next_post_id', function(err, pid) {
|
||||
RDB.handle(err);
|
||||
|
||||
plugins.fireHook('filter:post.save', content, function(content) {
|
||||
plugins.fireHook('filter:post.save', content, function(err, newContent) {
|
||||
if (!err) content = newContent;
|
||||
|
||||
var timestamp = Date.now(),
|
||||
postData = {
|
||||
'pid': pid,
|
||||
@@ -337,7 +340,9 @@ var RDB = require('./redis.js'),
|
||||
|
||||
async.parallel({
|
||||
content: function(next) {
|
||||
plugins.fireHook('filter:post.get', postData, function(postData) {
|
||||
plugins.fireHook('filter:post.get', postData, function(err, newPostData) {
|
||||
if (!err) postData = newPostData;
|
||||
|
||||
postTools.parse(postData.content, function(err, content) {
|
||||
next(null, content);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user