From 75c36abd75b9fee7829a63560cd91f3242c3e83c Mon Sep 17 00:00:00 2001 From: Akif9748 Date: Mon, 29 Aug 2022 16:43:57 +0300 Subject: [PATCH] fix for pages --- APIDOCS.md | 2 +- routes/threads.js | 4 ++-- views/thread.ejs | 12 ++++-------- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/APIDOCS.md b/APIDOCS.md index 79bcc1f..5886492 100644 --- a/APIDOCS.md +++ b/APIDOCS.md @@ -22,7 +22,7 @@ But in front end, the API will works with session. - POST `/api/users/:id/admin` for give admin permissions for a user. - GET `/api/threads/:id` for fetch thread. -- GET `/api/threads/:id/messages/:limit` for fetch messages in thread. +- GET `/api/threads/:id/messages/` for fetch messages in thread. - POST `/api/threads` for create thread. - POST `/api/threads/:id/delete` for delete thread. - POST `/api/threads/:id/undelete` for undelete thread. diff --git a/routes/threads.js b/routes/threads.js index e539a0d..769b779 100644 --- a/routes/threads.js +++ b/routes/threads.js @@ -22,10 +22,10 @@ app.get("/:id/", async (req, res) => { const thread = await ThreadModel.get(id) if (thread && (user?.admin || !thread.deleted)) { thread.views++; - const query = { threadID: id }; + const query = { threadID: id }; if (!user || !user.admin) query.deleted = false; - const messages = await MessageModel.find(query).sort({ time: 1 }).skip(page * 10).limit(page * 10 + 10) + const messages = await MessageModel.find(query).sort({ time: 1 }).limit(10).skip(page * 10) .then(messages => messages.map(message => { message.content = message.content.replaceAll("&", "&") .replaceAll("<", "<").replaceAll(">", ">") diff --git a/views/thread.ejs b/views/thread.ejs index 6c774cb..99544ad 100644 --- a/views/thread.ejs +++ b/views/thread.ejs @@ -65,7 +65,7 @@ <% if (!message.deleted){ %> Delete Edit - <% }else if (user.admin){ %> + <% }else { %> Undelete <% } %> @@ -92,13 +92,11 @@
- - <% if (user){ %> - + <%} else {%> - Login for send + Login for send <% }%>
@@ -111,9 +109,7 @@
- <% for(let i=0;i <= Math.ceil(messages.length/10) ;i++){ %> - <%= i+1 %> - <% } %> + <%= page+1 %>