Files
NodeBB/src/posts/parse.js

41 lines
1013 B
JavaScript
Raw Normal View History

'use strict';
2016-02-23 13:08:38 +02:00
var cache = require('./cache');
var plugins = require('../plugins');
module.exports = function(Posts) {
Posts.parsePost = function(postData, callback) {
postData.content = postData.content || '';
2015-11-26 23:34:55 -05:00
if (postData.pid && cache.has(postData.pid)) {
postData.content = cache.get(postData.pid);
return callback(null, postData);
}
// Casting post content into a string, just in case
if (typeof postData.content !== 'string') {
postData.content = postData.content.toString();
}
plugins.fireHook('filter:parse.post', {postData: postData}, function(err, data) {
if (err) {
return callback(err);
}
2015-11-16 16:51:19 -05:00
2015-11-25 12:30:43 -05:00
if (global.env === 'production' && data.postData.pid) {
2015-11-16 16:51:19 -05:00
cache.set(data.postData.pid, data.postData.content);
}
callback(null, data.postData);
});
};
Posts.parseSignature = function(userData, uid, callback) {
userData.signature = userData.signature || '';
plugins.fireHook('filter:parse.signature', {userData: userData, uid: uid}, callback);
};
2015-11-26 23:34:55 -05:00
};