mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-01 13:20:41 +01:00
feat: #9234, add pagination to /api/recent/posts/:term?
This commit is contained in:
@@ -30,6 +30,10 @@ postsController.redirectToPost = async function (req, res, next) {
|
||||
};
|
||||
|
||||
postsController.getRecentPosts = async function (req, res) {
|
||||
const data = await posts.getRecentPosts(req.uid, 0, 19, req.params.term);
|
||||
const page = parseInt(req.query.page, 10) || 1;
|
||||
const postsPerPage = 20;
|
||||
const start = Math.max(0, (page - 1) * postsPerPage);
|
||||
const stop = start + postsPerPage - 1;
|
||||
const data = await posts.getRecentPosts(req.uid, start, stop, req.params.term);
|
||||
res.json(data);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user