fix: dont overwrite postIndex

if its not on the current page
This commit is contained in:
Barış Soner Uşaklı
2023-06-22 22:26:08 -04:00
parent cbd98c1b28
commit c21d7dbc7e

View File

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