mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 19:46:01 +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;
|
break;
|
||||||
case 'action':
|
case 'action':
|
||||||
@@ -185,7 +185,7 @@ var fs = require('fs'),
|
|||||||
} else {
|
} else {
|
||||||
// Otherwise, this hook contains no methods
|
// Otherwise, this hook contains no methods
|
||||||
var returnVal = (Array.isArray(args) ? args[0] : args);
|
var returnVal = (Array.isArray(args) ? args[0] : args);
|
||||||
if (callback) callback(returnVal);
|
if (callback) callback(err, returnVal);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
isActive: function(id, callback) {
|
isActive: function(id, callback) {
|
||||||
|
|||||||
@@ -102,8 +102,8 @@ var RDB = require('./redis.js'),
|
|||||||
|
|
||||||
PostTools.privileges(pid, uid, function(privileges) {
|
PostTools.privileges(pid, uid, function(privileges) {
|
||||||
if (privileges.editable) {
|
if (privileges.editable) {
|
||||||
plugins.fireHook('filter:post.save', content, function(parsedContent) {
|
plugins.fireHook('filter:post.save', content, function(err, parsedContent) {
|
||||||
content = parsedContent;
|
if (!err) content = parsedContent;
|
||||||
success();
|
success();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -193,8 +193,8 @@ var RDB = require('./redis.js'),
|
|||||||
PostTools.parse = function(raw, callback) {
|
PostTools.parse = function(raw, callback) {
|
||||||
raw = raw || '';
|
raw = raw || '';
|
||||||
|
|
||||||
plugins.fireHook('filter:post.parse', raw, function(parsed) {
|
plugins.fireHook('filter:post.parse', raw, function(err, parsed) {
|
||||||
callback(null, 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) {
|
Posts.getPostData = function(pid, callback) {
|
||||||
RDB.hgetall('post:' + pid, function(err, data) {
|
RDB.hgetall('post:' + pid, function(err, data) {
|
||||||
if (err === null) {
|
if (err === null) {
|
||||||
plugins.fireHook('filter:post.get', data, function(data) {
|
plugins.fireHook('filter:post.get', data, function(err, newData) {
|
||||||
callback(data);
|
if (!err) callback(newData);
|
||||||
|
else callback(data);
|
||||||
});
|
});
|
||||||
} else
|
} else
|
||||||
console.log(err);
|
console.log(err);
|
||||||
@@ -287,7 +288,9 @@ var RDB = require('./redis.js'),
|
|||||||
RDB.incr('global:next_post_id', function(err, pid) {
|
RDB.incr('global:next_post_id', function(err, pid) {
|
||||||
RDB.handle(err);
|
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(),
|
var timestamp = Date.now(),
|
||||||
postData = {
|
postData = {
|
||||||
'pid': pid,
|
'pid': pid,
|
||||||
@@ -337,7 +340,9 @@ var RDB = require('./redis.js'),
|
|||||||
|
|
||||||
async.parallel({
|
async.parallel({
|
||||||
content: function(next) {
|
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) {
|
postTools.parse(postData.content, function(err, content) {
|
||||||
next(null, content);
|
next(null, content);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user