From c21d7dbc7ee86cd29faa603d68908d0d88884a5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Thu, 22 Jun 2023 22:26:08 -0400 Subject: [PATCH] fix: dont overwrite postIndex if its not on the current page --- src/controllers/topics.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/controllers/topics.js b/src/controllers/topics.js index 3fa41c4ee8..d177da7cbc 100644 --- a/src/controllers/topics.js +++ b/src/controllers/topics.js @@ -76,7 +76,11 @@ topicsController.get = async function getTopic(req, res, next) { if (!req.query.page) { currentPage = calculatePageFromIndex(postIndex, settings); } else { - postIndex = ((currentPage - 1) * settings.postsPerPage) + 1; + const top = ((currentPage - 1) * settings.postsPerPage) + 1; + const bottom = top + settings.postsPerPage; + if (!req.params.post_index || (postIndex < top || postIndex > bottom)) { + postIndex = top; + } } } const { start, stop } = calculateStartStop(currentPage, postIndex, settings);