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. - POST `/api/users/:id/admin` for give admin permissions for a user.
- GET `/api/threads/:id` for fetch thread. - 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` for create thread.
- POST `/api/threads/:id/delete` for delete thread. - POST `/api/threads/:id/delete` for delete thread.
- POST `/api/threads/:id/undelete` for undelete thread. - POST `/api/threads/:id/undelete` for undelete thread.

View file

@ -22,10 +22,10 @@ app.get("/:id/", async (req, res) => {
const thread = await ThreadModel.get(id) const thread = await ThreadModel.get(id)
if (thread && (user?.admin || !thread.deleted)) { if (thread && (user?.admin || !thread.deleted)) {
thread.views++; thread.views++;
const query = { threadID: id }; const query = { threadID: id };
if (!user || !user.admin) query.deleted = false; 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 => { .then(messages => messages.map(message => {
message.content = message.content.replaceAll("&", "&") message.content = message.content.replaceAll("&", "&")
.replaceAll("<", "&lt;").replaceAll(">", "&gt;") .replaceAll("<", "&lt;").replaceAll(">", "&gt;")

View file

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