mirror of
https://github.com/Akif9748/akf-forum.git
synced 2024-11-26 13:20:41 +03:00
Major bug fix
This commit is contained in:
parent
74b6b73b72
commit
bfac0b16af
1 changed files with 4 additions and 4 deletions
|
@ -1,6 +1,6 @@
|
||||||
const { Router } = require("express");
|
const { Router } = require("express");
|
||||||
const app = Router();
|
const app = Router();
|
||||||
const {clearContent} = require("../lib");
|
const { clearContent } = require("../lib");
|
||||||
const { ThreadModel, MessageModel } = require("../models")
|
const { ThreadModel, MessageModel } = require("../models")
|
||||||
|
|
||||||
app.get("/", async (req, res) => {
|
app.get("/", async (req, res) => {
|
||||||
|
@ -22,16 +22,16 @@ app.get("/:id/", async (req, res) => {
|
||||||
const page = Number(req.query.page || 0);
|
const page = Number(req.query.page || 0);
|
||||||
|
|
||||||
const thread = await ThreadModel.get(id)
|
const thread = await ThreadModel.get(id)
|
||||||
|
if (thread && (user?.admin || !thread.deleted)) {
|
||||||
thread.count = await thread.messageCount(user?.admin);
|
thread.count = await thread.messageCount(user?.admin);
|
||||||
thread.pages = Math.ceil(thread.count / 10);
|
thread.pages = Math.ceil(thread.count / 10);
|
||||||
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 Promise.all(await MessageModel.find(query).sort({ time: 1 }).limit(10).skip(page * 10)
|
const messages = await Promise.all(await MessageModel.find(query).sort({ time: 1 }).limit(10).skip(page * 10)
|
||||||
.then(messages => messages.map(async message => {
|
.then(messages => messages.map(async message => {
|
||||||
message.content =clearContent( message.content)
|
message.content = clearContent(message.content)
|
||||||
return await message.get_author();
|
return await message.get_author();
|
||||||
})));
|
})));
|
||||||
res.reply("thread", { page, thread, messages, scroll: req.query.scroll || messages[0]?.id });
|
res.reply("thread", { page, thread, messages, scroll: req.query.scroll || messages[0]?.id });
|
||||||
|
|
Loading…
Reference in a new issue