clamp page query param in thread view
This commit is contained in:
parent
96922fdd76
commit
8e7b167bc2
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user