mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-08 15:05:46 +01:00
move methods from posts to posts/data
This commit is contained in:
107
src/posts.js
107
src/posts.js
@@ -12,6 +12,7 @@ var plugins = require('./plugins');
|
|||||||
|
|
||||||
var Posts = module.exports;
|
var Posts = module.exports;
|
||||||
|
|
||||||
|
require('./posts/data')(Posts);
|
||||||
require('./posts/create')(Posts);
|
require('./posts/create')(Posts);
|
||||||
require('./posts/delete')(Posts);
|
require('./posts/delete')(Posts);
|
||||||
require('./posts/edit')(Posts);
|
require('./posts/edit')(Posts);
|
||||||
@@ -95,112 +96,6 @@ Posts.getPostSummariesFromSet = function (set, uid, start, stop, callback) {
|
|||||||
], callback);
|
], callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
Posts.getPostData = function (pid, callback) {
|
|
||||||
async.waterfall([
|
|
||||||
function (next) {
|
|
||||||
db.getObject('post:' + pid, next);
|
|
||||||
},
|
|
||||||
function (data, next) {
|
|
||||||
plugins.fireHook('filter:post.getPostData', { post: data }, next);
|
|
||||||
},
|
|
||||||
function (data, next) {
|
|
||||||
next(null, data.post);
|
|
||||||
},
|
|
||||||
], callback);
|
|
||||||
};
|
|
||||||
|
|
||||||
Posts.getPostsData = function (pids, callback) {
|
|
||||||
async.waterfall([
|
|
||||||
function (next) {
|
|
||||||
db.getObjects(pids.map(pid => 'post:' + pid), next);
|
|
||||||
},
|
|
||||||
function (data, next) {
|
|
||||||
plugins.fireHook('filter:post.getPostsData', { posts: data }, next);
|
|
||||||
},
|
|
||||||
function (data, next) {
|
|
||||||
next(null, data.posts);
|
|
||||||
},
|
|
||||||
], callback);
|
|
||||||
};
|
|
||||||
|
|
||||||
Posts.getPostField = function (pid, field, callback) {
|
|
||||||
async.waterfall([
|
|
||||||
function (next) {
|
|
||||||
Posts.getPostFields(pid, [field], next);
|
|
||||||
},
|
|
||||||
function (data, next) {
|
|
||||||
next(null, data[field]);
|
|
||||||
},
|
|
||||||
], callback);
|
|
||||||
};
|
|
||||||
|
|
||||||
Posts.getPostFields = function (pid, fields, callback) {
|
|
||||||
async.waterfall([
|
|
||||||
function (next) {
|
|
||||||
db.getObjectFields('post:' + pid, fields, next);
|
|
||||||
},
|
|
||||||
function (data, next) {
|
|
||||||
data.pid = pid;
|
|
||||||
|
|
||||||
plugins.fireHook('filter:post.getFields', { posts: [data], fields: fields }, next);
|
|
||||||
},
|
|
||||||
function (data, next) {
|
|
||||||
next(null, (data && Array.isArray(data.posts) && data.posts.length) ? data.posts[0] : null);
|
|
||||||
},
|
|
||||||
], callback);
|
|
||||||
};
|
|
||||||
|
|
||||||
Posts.getPostsFields = function (pids, fields, callback) {
|
|
||||||
if (!Array.isArray(pids) || !pids.length) {
|
|
||||||
return callback(null, []);
|
|
||||||
}
|
|
||||||
|
|
||||||
var keys = pids.map(function (pid) {
|
|
||||||
return 'post:' + pid;
|
|
||||||
});
|
|
||||||
|
|
||||||
async.waterfall([
|
|
||||||
function (next) {
|
|
||||||
db.getObjectsFields(keys, fields, next);
|
|
||||||
},
|
|
||||||
function (posts, next) {
|
|
||||||
plugins.fireHook('filter:post.getFields', { posts: posts, fields: fields }, next);
|
|
||||||
},
|
|
||||||
function (data, next) {
|
|
||||||
next(null, (data && Array.isArray(data.posts)) ? data.posts : null);
|
|
||||||
},
|
|
||||||
], callback);
|
|
||||||
};
|
|
||||||
|
|
||||||
Posts.setPostField = function (pid, field, value, callback) {
|
|
||||||
async.waterfall([
|
|
||||||
function (next) {
|
|
||||||
db.setObjectField('post:' + pid, field, value, next);
|
|
||||||
},
|
|
||||||
function (next) {
|
|
||||||
var data = {
|
|
||||||
pid: pid,
|
|
||||||
};
|
|
||||||
data[field] = value;
|
|
||||||
plugins.fireHook('action:post.setFields', { data: data });
|
|
||||||
next();
|
|
||||||
},
|
|
||||||
], callback);
|
|
||||||
};
|
|
||||||
|
|
||||||
Posts.setPostFields = function (pid, data, callback) {
|
|
||||||
async.waterfall([
|
|
||||||
function (next) {
|
|
||||||
db.setObject('post:' + pid, data, next);
|
|
||||||
},
|
|
||||||
function (next) {
|
|
||||||
data.pid = pid;
|
|
||||||
plugins.fireHook('action:post.setFields', { data: data });
|
|
||||||
next();
|
|
||||||
},
|
|
||||||
], callback);
|
|
||||||
};
|
|
||||||
|
|
||||||
Posts.getPidIndex = function (pid, tid, topicPostSort, callback) {
|
Posts.getPidIndex = function (pid, tid, topicPostSort, callback) {
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
|
|||||||
114
src/posts/data.js
Normal file
114
src/posts/data.js
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var async = require('async');
|
||||||
|
|
||||||
|
var db = require('../database');
|
||||||
|
var plugins = require('../plugins');
|
||||||
|
|
||||||
|
module.exports = function (Posts) {
|
||||||
|
Posts.getPostData = function (pid, callback) {
|
||||||
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
db.getObject('post:' + pid, next);
|
||||||
|
},
|
||||||
|
function (data, next) {
|
||||||
|
plugins.fireHook('filter:post.getPostData', { post: data }, next);
|
||||||
|
},
|
||||||
|
function (data, next) {
|
||||||
|
next(null, data.post);
|
||||||
|
},
|
||||||
|
], callback);
|
||||||
|
};
|
||||||
|
|
||||||
|
Posts.getPostsData = function (pids, callback) {
|
||||||
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
db.getObjects(pids.map(pid => 'post:' + pid), next);
|
||||||
|
},
|
||||||
|
function (data, next) {
|
||||||
|
plugins.fireHook('filter:post.getPostsData', { posts: data }, next);
|
||||||
|
},
|
||||||
|
function (data, next) {
|
||||||
|
next(null, data.posts);
|
||||||
|
},
|
||||||
|
], callback);
|
||||||
|
};
|
||||||
|
|
||||||
|
Posts.getPostField = function (pid, field, callback) {
|
||||||
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
Posts.getPostFields(pid, [field], next);
|
||||||
|
},
|
||||||
|
function (data, next) {
|
||||||
|
next(null, data[field]);
|
||||||
|
},
|
||||||
|
], callback);
|
||||||
|
};
|
||||||
|
|
||||||
|
Posts.getPostFields = function (pid, fields, callback) {
|
||||||
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
db.getObjectFields('post:' + pid, fields, next);
|
||||||
|
},
|
||||||
|
function (data, next) {
|
||||||
|
data.pid = pid;
|
||||||
|
|
||||||
|
plugins.fireHook('filter:post.getFields', { posts: [data], fields: fields }, next);
|
||||||
|
},
|
||||||
|
function (data, next) {
|
||||||
|
next(null, (data && Array.isArray(data.posts) && data.posts.length) ? data.posts[0] : null);
|
||||||
|
},
|
||||||
|
], callback);
|
||||||
|
};
|
||||||
|
|
||||||
|
Posts.getPostsFields = function (pids, fields, callback) {
|
||||||
|
if (!Array.isArray(pids) || !pids.length) {
|
||||||
|
return callback(null, []);
|
||||||
|
}
|
||||||
|
|
||||||
|
var keys = pids.map(function (pid) {
|
||||||
|
return 'post:' + pid;
|
||||||
|
});
|
||||||
|
|
||||||
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
db.getObjectsFields(keys, fields, next);
|
||||||
|
},
|
||||||
|
function (posts, next) {
|
||||||
|
plugins.fireHook('filter:post.getFields', { posts: posts, fields: fields }, next);
|
||||||
|
},
|
||||||
|
function (data, next) {
|
||||||
|
next(null, (data && Array.isArray(data.posts)) ? data.posts : null);
|
||||||
|
},
|
||||||
|
], callback);
|
||||||
|
};
|
||||||
|
|
||||||
|
Posts.setPostField = function (pid, field, value, callback) {
|
||||||
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
db.setObjectField('post:' + pid, field, value, next);
|
||||||
|
},
|
||||||
|
function (next) {
|
||||||
|
var data = {
|
||||||
|
pid: pid,
|
||||||
|
};
|
||||||
|
data[field] = value;
|
||||||
|
plugins.fireHook('action:post.setFields', { data: data });
|
||||||
|
next();
|
||||||
|
},
|
||||||
|
], callback);
|
||||||
|
};
|
||||||
|
|
||||||
|
Posts.setPostFields = function (pid, data, callback) {
|
||||||
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
db.setObject('post:' + pid, data, next);
|
||||||
|
},
|
||||||
|
function (next) {
|
||||||
|
data.pid = pid;
|
||||||
|
plugins.fireHook('action:post.setFields', { data: data });
|
||||||
|
next();
|
||||||
|
},
|
||||||
|
], callback);
|
||||||
|
};
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user