mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-04 11:31:23 +01:00
refactor: deprecate socket method posts.getPidIndex
This commit is contained in:
@@ -41,6 +41,16 @@ postsAPI.get = async function (caller, data) {
|
||||
return post;
|
||||
};
|
||||
|
||||
postsAPI.getIndex = async (caller, { pid, sort }) => {
|
||||
const tid = await posts.getPostField(pid, 'tid');
|
||||
const topicPrivileges = await privileges.topics.get(tid, caller.uid);
|
||||
if (!topicPrivileges.read || !topicPrivileges['topics:read']) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return await posts.getPidIndex(pid, tid, sort);
|
||||
};
|
||||
|
||||
postsAPI.getSummary = async (caller, { pid }) => {
|
||||
const tid = await posts.getPostField(pid, 'tid');
|
||||
const topicPrivileges = await privileges.topics.get(tid, caller.uid);
|
||||
|
||||
@@ -44,6 +44,18 @@ Posts.get = async (req, res) => {
|
||||
helpers.formatApiResponse(200, res, post);
|
||||
};
|
||||
|
||||
Posts.getIndex = async (req, res) => {
|
||||
const { pid } = req.params;
|
||||
const { sort } = req.body;
|
||||
|
||||
const index = await api.posts.getIndex(req, { pid, sort });
|
||||
if (index === null) {
|
||||
return helpers.formatApiResponse(404, res, new Error('[[error:no-post]]'));
|
||||
}
|
||||
|
||||
helpers.formatApiResponse(200, res, { index });
|
||||
};
|
||||
|
||||
Posts.getSummary = async (req, res) => {
|
||||
const post = await api.posts.getSummary(req, { pid: req.params.pid });
|
||||
if (!post) {
|
||||
|
||||
@@ -15,6 +15,7 @@ module.exports = function () {
|
||||
setupApiRoute(router, 'put', '/:pid', [middleware.ensureLoggedIn, middleware.checkRequired.bind(null, ['content'])], controllers.write.posts.edit);
|
||||
setupApiRoute(router, 'delete', '/:pid', middlewares, controllers.write.posts.purge);
|
||||
|
||||
setupApiRoute(router, 'get', '/:pid/index', [middleware.assert.post], controllers.write.posts.getIndex);
|
||||
setupApiRoute(router, 'get', '/:pid/raw', [middleware.assert.post], controllers.write.posts.getRaw);
|
||||
setupApiRoute(router, 'get', '/:pid/summary', [middleware.assert.post], controllers.write.posts.getSummary);
|
||||
|
||||
|
||||
@@ -28,6 +28,8 @@ SocketPosts.getRawPost = async function (socket, pid) {
|
||||
};
|
||||
|
||||
SocketPosts.getPostSummaryByIndex = async function (socket, data) {
|
||||
sockets.warnDeprecated(socket, 'GET /api/v3/posts/byIndex/:index/summary?tid=:tid');
|
||||
|
||||
if (data.index < 0) {
|
||||
data.index = 0;
|
||||
}
|
||||
@@ -42,14 +44,7 @@ SocketPosts.getPostSummaryByIndex = async function (socket, data) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const topicPrivileges = await privileges.topics.get(data.tid, socket.uid);
|
||||
if (!topicPrivileges['topics:read']) {
|
||||
throw new Error('[[error:no-privileges]]');
|
||||
}
|
||||
|
||||
const postsData = await posts.getPostSummaryByPids([pid], socket.uid, { stripTags: false });
|
||||
posts.modifyPostByPrivilege(postsData[0], topicPrivileges);
|
||||
return postsData[0];
|
||||
return await api.posts.getSummary(socket, { pid });
|
||||
};
|
||||
|
||||
SocketPosts.getPostTimestampByIndex = async function (socket, data) {
|
||||
@@ -83,10 +78,16 @@ SocketPosts.getCategory = async function (socket, pid) {
|
||||
};
|
||||
|
||||
SocketPosts.getPidIndex = async function (socket, data) {
|
||||
sockets.warnDeprecated(socket, 'GET /api/v3/posts/:pid/index');
|
||||
|
||||
if (!data) {
|
||||
throw new Error('[[error:invalid-data]]');
|
||||
}
|
||||
return await posts.getPidIndex(data.pid, data.tid, data.topicPostSort);
|
||||
|
||||
return await api.posts.getIndex(socket, {
|
||||
pid: data.pid,
|
||||
sort: data.topicPostSort,
|
||||
});
|
||||
};
|
||||
|
||||
SocketPosts.getReplies = async function (socket, pid) {
|
||||
|
||||
Reference in New Issue
Block a user