feat: #9234, add pagination to /api/recent/posts/:term?

v1.18.x
Barış Soner Uşaklı 4 years ago
parent 2bc74cffe6
commit fffdc4e0ca

@ -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);
};

Loading…
Cancel
Save