From 8ee97ea4973e198884602084c7212c0dafafa9eb Mon Sep 17 00:00:00 2001 From: Akif9748 Date: Wed, 24 Aug 2022 22:39:38 +0300 Subject: [PATCH] \n =>
--- README.md | 1 + public/js/thread.js | 11 +++-------- routes/{message.js => messages.js} | 0 routes/register.js | 1 + routes/threads.js | 8 ++------ util/APIDOCS.md | 2 +- views/index.ejs | 4 ++-- 7 files changed, 10 insertions(+), 17 deletions(-) rename routes/{message.js => messages.js} (100%) diff --git a/README.md b/README.md index 9170f0e..ae4db8e 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ And, you can learn about API in `util/APIDOCS.md`. | Ratelimit | 🟢 | HIGH | | Send | 🟢 | HIGH | | Delete | 🟢 | HIGH | +| Regex for scripts | 🔴 | HIGH | | Undelete | 🔴 | MEDIUM | | React | 🟢 | MEDIUM | | Edit | 🔴 | MEDIUM | diff --git a/public/js/thread.js b/public/js/thread.js index 9a2639d..0127468 100644 --- a/public/js/thread.js +++ b/public/js/thread.js @@ -16,7 +16,7 @@ function renderMessage(message) { ${message.author.name}: -

${message.content}


+

${message.content.replaceAll("\n","
")}


${!message.deleted ? `
@@ -49,14 +49,9 @@ function renderMessage(message) { } else - for (const message of result) { - - const arr = Object.values(message.react || {}) - - message.reactCount = arr.filter(Boolean).length - arr.filter(x => !x).length; - + for (const message of result) renderMessage(message); - } + window.scrollTo(0, document.body.scrollHeight); })(); diff --git a/routes/message.js b/routes/messages.js similarity index 100% rename from routes/message.js rename to routes/messages.js diff --git a/routes/register.js b/routes/register.js index 881c6dd..1a82133 100644 --- a/routes/register.js +++ b/routes/register.js @@ -1,6 +1,7 @@ const { UserModel, SecretModel } = require("../models"); const { Router } = require("express") const bcrypt = require("bcrypt"); +const rateLimit = require('express-rate-limit') const app = Router(); diff --git a/routes/threads.js b/routes/threads.js index d24e722..175d1ac 100644 --- a/routes/threads.js +++ b/routes/threads.js @@ -1,6 +1,5 @@ const { Router } = require("express"); const app = Router(); -const rateLimit = require('express-rate-limit') const { ThreadModel, MessageModel } = require("../models") @@ -32,11 +31,8 @@ app.get("/:id", async (req, res) => { if (thread && (user?.admin || !thread.deleted)) { const messages = await Promise.all(thread.messages.map(async id => { - const message = await MessageModel.get(id) - const arr = Object.values(message.react) - message.reactCount = arr.filter(Boolean).length - arr.filter(x => !x).length; - - return user?.admin || !message?.deleted ? message : null; + const message = await MessageModel.get(id) + return user?.admin || !message?.deleted ? message.toObject({ virtuals: true }) : null; })); res.render("thread", { thread, messages, user,scroll:req.query.scroll || false }); diff --git a/util/APIDOCS.md b/util/APIDOCS.md index c214318..b3e80b0 100644 --- a/util/APIDOCS.md +++ b/util/APIDOCS.md @@ -32,7 +32,7 @@ You need this headers for send request to API: - POST `/api/messages/:id/react/:type` for react to a message. ### Example request: -```GET /api/message/1``` +```GET /api/messages/1``` #### Example API Output: ```json diff --git a/views/index.ejs b/views/index.ejs index 2f1148d..7a06bec 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -5,8 +5,8 @@ <%- include("extra/navbar") %> - -<% if (user) { %> + + <% if (user) { %>

Welcome, > <%= user.name %> alt=<%= user.name %>>