clamp page query param in thread view

This commit is contained in:
Lera Elvoé 2025-05-21 17:34:02 +03:00
parent 96922fdd76
commit 8e7b167bc2
Signed by: yagich
SSH Key Fingerprint: SHA256:6xjGb6uA7lAVcULa7byPEN//rQ0wPoG+UzYVMfZnbvc

View File

@ -69,6 +69,11 @@ app:get("thread", "/:slug", function(self)
end
self.thread = thread
local post_count = Posts:count(db.clause({
thread_id = thread.id
}))
self.pages = math.ceil(post_count / POSTS_PER_PAGE)
if self.params.after then
local after_id = tonumber(self.params.after)
local post_position = Posts:count(db.clause({
@ -77,13 +82,9 @@ app:get("thread", "/:slug", function(self)
}))
self.page = math.floor((post_position - 1) / POSTS_PER_PAGE) + 1
else
self.page = tonumber(self.params.page) or 1
self.page = math.max(1, math.min(tonumber(self.params.page) or 1, self.pages))
end
local post_count = Posts:count(db.clause({
thread_id = thread.id
}))
self.pages = math.ceil(post_count / POSTS_PER_PAGE)
-- self.page = math.max(1, math.min(self.page, self.pages))
local posts = db.query([[
SELECT