From 54142719245ffa6c5fe7d6c0a1919c86e5403c57 Mon Sep 17 00:00:00 2001 From: Akif9748 Date: Thu, 11 Aug 2022 18:15:27 +0300 Subject: [PATCH] String fixes --- README.md | 1 + public/js/thread.js | 3 ++- routes/.js | 6 +++--- routes/api/routes/messages.js | 9 +++------ routes/api/routes/threads.js | 6 +++--- routes/api/routes/users.js | 10 +++++----- 6 files changed, 17 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 312403f..f04a392 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,7 @@ And, you can learn about API in `util/APIDOCS.md`. | To do | Is done? | Priority | | ----- | -------- | -------- | | Footer | 🟡 | LOW | +| auto-scroll | 🟡 | LOW | | Multi-theme support | 🔴 | LOW | | Search | 🔴 | MEDIUM | | Better view | 🟢 | MEDIUM | diff --git a/public/js/thread.js b/public/js/thread.js index d87f8fa..143e477 100644 --- a/public/js/thread.js +++ b/public/js/thread.js @@ -57,7 +57,8 @@ function renderMessage(message) { renderMessage(message); } - + window.scrollTo(0, document.body.scrollHeight); + })(); diff --git a/routes/.js b/routes/.js index 16af02e..88feade 100644 --- a/routes/.js +++ b/routes/.js @@ -5,9 +5,9 @@ const app = Router(); app.get("/", async (req, res) => { const mem = process.memoryUsage().heapUsed / Math.pow(2, 20), - users = await UserModel.count({}), - threads = await ThreadModel.count({}), - messages = await MessageModel.count({}), + users = await UserModel.count({deleted:false}), + threads = await ThreadModel.count({deleted:false}), + messages = await MessageModel.count({deleted:false}), user = req.user; res.render("index", { mem, user, users, threads, messages }) diff --git a/routes/api/routes/messages.js b/routes/api/routes/messages.js index 86ebba0..0687156 100644 --- a/routes/api/routes/messages.js +++ b/routes/api/routes/messages.js @@ -8,12 +8,9 @@ const app = Router(); app.get("/:id", async (req, res) => { - - const { id = null } = req.params; - if (!id) return res.error(400, "Missing id in query") const message = await MessageModel.get(id); - if (!message || (message.deleted && req.user && !req.user.admin)) return res.error(404, "We have not got any message declared as this id."); + if (!message || (message.deleted && req.user && !req.user.admin)) return res.error(404, `We don't have any thread with id ${id}.`); res.complate(message); @@ -32,7 +29,7 @@ app.post("/", rateLimit({ const thread = await ThreadModel.get(threadID); - if (!thread) return res.error(404, "We have not got this thread."); + if (!thread) return res.error(404, `We don't have any thread with id ${threadID}.`); const message = await new MessageModel({ content, author: req.user, threadID: thread.id }).takeId(); await message.save(); @@ -55,7 +52,7 @@ app.post("/:id/react/:type", async (req, res) => { const arr = Object.values(message.react) res.complate(arr.filter(Boolean).length - arr.filter(x => !x).length) - } else error(res, 404, "We have not got this Message for reacting."); + } else error(res, 404, `We don't have any message with id ${req.params.id}.`); }); diff --git a/routes/api/routes/threads.js b/routes/api/routes/threads.js index 5fb1d3e..cfb8251 100644 --- a/routes/api/routes/threads.js +++ b/routes/api/routes/threads.js @@ -11,7 +11,7 @@ app.get("/:id", async (req, res) => { if (thread && (req.user?.admin || !thread.deleted)) res.complate(thread); else - return res.error(404, "We don't have any thread with this id."); + return res.error(404, `We don't have any thread with id ${id}.`); }); @@ -19,7 +19,7 @@ app.get("/:id", async (req, res) => { app.get("/:id/messages/", async (req, res) => { - const { id = null } = req.params; + const { id } = req.params; const limit = Number(req.query.limit); const query = { threadID: id }; @@ -54,7 +54,7 @@ app.post("/", async (req, res) => { app.post("/:id/delete", async (req, res) => { const thread = await ThreadModel.get(req.params.id); - if (!thread || thread.deleted) return res.error(404, "We don't have any thread with this id."); + if (!thread || thread.deleted) return res.error(404, `We don't have any thread with id ${req.params.id}.`); const user = req.user; if (user.id != thread.authorID && !user.admin) return res.error(403, "You have not got permission for this."); diff --git a/routes/api/routes/users.js b/routes/api/routes/users.js index a5fe064..af7a2c1 100644 --- a/routes/api/routes/users.js +++ b/routes/api/routes/users.js @@ -6,9 +6,9 @@ const app = Router(); app.get("/:id", async (req, res) => { const { id = null } = req.params; - if (!id) return res.error(400, "Missing id in query") + const member = await UserModel.get(id); - if (!member || (member.deleted && !req.user.admin)) return res.error(404, "We have not got any user declared as this id."); + if (!member || (member.deleted && !req.user.admin)) return res.error(404, `We don't have any user with id ${id}.`); res.complate(member); @@ -22,7 +22,7 @@ app.post("/:id/delete/", async (req, res) => { const { id = null } = req.params; const member = await UserModel.get(id); - if (!member || member.deleted) return res.error(404, "We have not got any user declared as this id."); + if (!member || member.deleted) return res.error(404, `We don't have any user with id ${id}.`); member.deleted = true; await member.save(); @@ -33,11 +33,11 @@ app.post("/:id/admin/", async (req, res) => { const user = req.user; - if (!user.admin) return res.error(403, "You have not got permissions for view to this page."); + if (!user.admin) return res.error(403, "You have not got permission for this."); const user2 = await UserModel.get(req.params.id); if (!user2) - return res.error(404, "This user is not available."); + return res.error(404, `We don't have any user with id ${id}.`); else { user2.admin = true;