view count for threads

This commit is contained in:
Akif9748 2022-08-28 15:00:53 +03:00
parent 1f737277b2
commit 98356a2a90
8 changed files with 95 additions and 170 deletions

View file

@ -58,7 +58,7 @@ Akf-forum has got an API for AJAX, other clients etc. And, you can learn about A
| Send | 🟢 | HIGH |
| Delete | 🟢 | HIGH |
| Regex for scripts | 🔴 | HIGH |
| Undelete | 🟡 | MEDIUM |
| Undelete | 🟢 | MEDIUM |
| React | 🟢 | MEDIUM |
| Edit | 🔴 | MEDIUM |

View file

@ -8,7 +8,8 @@ const schema = new mongoose.Schema({
title: String,
time: { type: Date, default: Date.now },
deleted: { type: Boolean, default: false },
messages: [String]
messages: [String],
views: { type: Number, default: 0 }
});

View file

@ -19,7 +19,10 @@
"bugs": {
"url": "https://github.com/Akif9748/akf-forum/issues"
},
"homepage": "https://akf-forum.herokuapp.com/",
"engines": {
"node": ">=16"
},
"homepage": "https://akf-forum.glitch.me/",
"dependencies": {
"bcrypt": "^5.0.1",
"body-parser": "^1.19.2",

View file

@ -28,7 +28,6 @@
textarea {
font-family: monospace;
background-color: var(--col-bg);
border: 2px solid var(--col-8);
color: var(--col-fg);
width: auto;
@ -130,36 +129,6 @@ button:hover {
/* NAVBAR: */
.navbar {
background-color: #333;
overflow: hidden;
}
.navbar a {
float: left;
color: var(--col-fg);
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
border-right: 3px solid var(--col-8);
}
.navbar a:hover {
background-color: var(--col-bg);
color: var(--col-fg);
}
.navbar h1:hover {
background-color: var(--col-bg);
color: var(--col-fg);
}
.navbar a.active {
background-color: var(--col-14);
color: var(--col-15);
}
.user {
margin: 0;
@ -211,52 +180,9 @@ img.logo {
}
/*
*****************************
FOOTER
*****************************
*/
.footer {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
background-color: var(--col-8);
color: white;
text-align: center;
}
.footer p {
font-size: 16px;
color: white;
}
/*
*****************************
ADMIN TEXT
*****************************
*/
.admin {
position: fixed;
left: 0;
top: 0;
height: 20px;
width: 100%;
text-align: center;
}
.admin p {
font-size: 16px;
margin: auto;
color: var(--col-15);
}
.admin a {
background-color: var(--col-13);
border: 2px solid var(--col-8);
height: 20px;
color: var(--col-15);
}
p {font-size: 18px;}

View file

@ -6,33 +6,26 @@ const { ThreadModel, MessageModel } = require("../models")
app.get("/", async (req, res) => {
const threads = await ThreadModel.find(req.user?.admin ? {} : { deleted: false }).limit(10);
const threads = await ThreadModel.find(req.user?.admin ? {} : { deleted: false })//.limit(10);
return res.reply("threads", { threads });
});
app.get("/create*", async (req, res) => {
res.reply("create_thread")
});
app.get("/create*", (req, res) => res.reply("create_thread"));
app.get("/:id", async (req, res) => {
const { id } = req.params;
const thread = await ThreadModel.get(id);
const user = req.user;
thread.views++;
if (thread && (user?.admin || !thread.deleted)) {
const messages = await Promise.all(thread.messages.map(async id => {
const message = await MessageModel.get(id)
return user?.admin || !message?.deleted ? message.toObject({ virtuals: true }) : null;
}));
res.reply("thread", { thread, messages, scroll: req.query.scroll || false });
} else
if (thread && (req.user?.admin || !thread.deleted))
res.reply("thread", { thread, scroll: req.query.scroll || false });
else
res.error(404, "We have not got this thread.");
thread.save();
});

View file

@ -14,6 +14,7 @@
<h1 style="font-size: 35px;color: #4d18e6;" ><%= thread.title %></h1>
<h1 style="font-size: 19px; " >View count: <%= thread.views %></h1>
<h2 style="display:inline;">By <a href="<%='/users/' + thread.author.id %>"> <%= thread.author.name %></a>
<img class="circle" src="<%=thread.author.avatar %>">

View file

@ -56,13 +56,14 @@
if (response.admin)
return alert("Making admin of " + response.name + " is success!");
}
} else if (e.target.id == "delete") {
const response = await request("/api/users/<%= member.id %>/delete");
if (!response.deleted) return
if (!response.deleted) return;
alert("User is deleted!");
location.reload()
}
});