mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 03:26:04 +01:00
codeclimate made me make my code ugly 😢
This commit is contained in:
@@ -8,16 +8,15 @@ var db = require('../database');
|
||||
var plugins = require('../plugins');
|
||||
var translator = require('../translator');
|
||||
|
||||
module.exports = function (Posts) {
|
||||
Posts.diffs = {};
|
||||
var Diffs = {};
|
||||
|
||||
Posts.diffs.exists = function (pid, callback) {
|
||||
Diffs.exists = function (pid, callback) {
|
||||
db.listLength('post:' + pid + ':diffs', function (err, numDiffs) {
|
||||
return callback(err, !!numDiffs);
|
||||
});
|
||||
};
|
||||
|
||||
Posts.diffs.get = function (pid, since, callback) {
|
||||
Diffs.get = function (pid, since, callback) {
|
||||
async.waterfall([
|
||||
async.apply(db.getListRange.bind(db), 'post:' + pid + ':diffs', 0, -1),
|
||||
function (timestamps, next) {
|
||||
@@ -33,11 +32,11 @@ module.exports = function (Posts) {
|
||||
], callback);
|
||||
};
|
||||
|
||||
Posts.diffs.list = function (pid, callback) {
|
||||
Diffs.list = function (pid, callback) {
|
||||
db.getListRange('post:' + pid + ':diffs', 0, -1, callback);
|
||||
};
|
||||
|
||||
Posts.diffs.save = function (pid, oldContent, newContent, callback) {
|
||||
Diffs.save = function (pid, oldContent, newContent, callback) {
|
||||
const now = Date.now();
|
||||
const patch = diff.createPatch('', newContent, oldContent);
|
||||
async.parallel([
|
||||
@@ -52,7 +51,9 @@ module.exports = function (Posts) {
|
||||
});
|
||||
};
|
||||
|
||||
Posts.diffs.load = function (pid, since, uid, callback) {
|
||||
Diffs.load = function (pid, since, uid, callback) {
|
||||
var Posts = require('../posts');
|
||||
|
||||
// Retrieves all diffs made since `since` and replays them to reconstruct what the post looked like at `since`
|
||||
since = parseInt(since, 10);
|
||||
|
||||
@@ -70,6 +71,21 @@ module.exports = function (Posts) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
postDiffLoad(data);
|
||||
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
plugins.fireHook('filter:parse.post', { postData: data.post }, next);
|
||||
},
|
||||
function (data, next) {
|
||||
data.postData.content = translator.escape(data.postData.content);
|
||||
next(null, data.postData);
|
||||
},
|
||||
], callback);
|
||||
});
|
||||
};
|
||||
|
||||
function postDiffLoad(data) {
|
||||
data.post = data.post[0];
|
||||
data.post.content = validator.unescape(data.post.content);
|
||||
|
||||
@@ -85,16 +101,12 @@ module.exports = function (Posts) {
|
||||
data.post.editor = null;
|
||||
|
||||
data.post.content = String(data.post.content || '');
|
||||
}
|
||||
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
plugins.fireHook('filter:parse.post', { postData: data.post }, next);
|
||||
},
|
||||
function (data, next) {
|
||||
data.postData.content = translator.escape(data.postData.content);
|
||||
next(null, data.postData);
|
||||
},
|
||||
], callback);
|
||||
module.exports = function (Posts) {
|
||||
Posts.diffs = {};
|
||||
|
||||
Object.keys(Diffs).forEach(function (property) {
|
||||
Posts.diffs[property] = Diffs[property];
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user