fix for pages

This commit is contained in:
Akif9748 2022-08-29 16:43:57 +03:00
parent 0ee3d3be8b
commit 75c36abd75
3 changed files with 7 additions and 11 deletions

View file

@ -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.

View file

@ -25,7 +25,7 @@ app.get("/:id/", async (req, res) => {
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("<", "&lt;").replaceAll(">", "&gt;")

View file

@ -65,7 +65,7 @@
<% if (!message.deleted){ %>
<a onclick="delete_message('<%=message.id %>');">Delete</a>
<a onclick="edit_message('<%=message.id %>');">Edit</a>
<% }else if (user.admin){ %>
<% }else { %>
<a onclick="undelete_message('<%=message.id %>');">Undelete</a>
<% } %>
</div>
@ -93,12 +93,10 @@
<textarea rows="4" cols="100" name="content"></textarea>
<input name="threadID" type="hidden" value="<%= thread.id %>"></input>
<% if (user){ %>
<button class="btn-primary">Send!</button>
<button class="btn-primary">Send!</button>
<%} else {%>
<a class="btn-outline-primary" href="/login?redirect=<%= thread.getLink() %>">Login for send</a>
<a class="btn-outline-primary" href="/login?redirect=<%= thread.getLink() %>">Login for send</a>
<% }%>
</form>
</div>
@ -111,9 +109,7 @@
<div class="numbers">
<% for(let i=0;i <= Math.ceil(messages.length/10) ;i++){ %>
<a class="number <%= i==page?'active':'' %>" href="<%= thread.getLink() %>?page=<%= i %>"><%= i+1 %></a>
<% } %>
<a class="number" href="<%= thread.getLink() %>?page=<%= page %>"><%= page+1 %></a>
</div>
<div class="after">