mirror of
https://github.com/Akif9748/akf-forum.git
synced 2024-11-22 20:10:40 +03:00
3lü ve güçlü
Co-authored-by: Sapphire1525 <Sapphire1525@users.noreply.github.com> Co-authored-by: inoaa79 <inoaa79@users.noreply.github.com>
This commit is contained in:
parent
0d4dd2c369
commit
4be2069587
11 changed files with 36 additions and 29 deletions
|
@ -75,7 +75,7 @@ And, you can learn about API in `util/APIDOCS.md`.
|
|||
| auto-scroll | 🟢 | LOW |
|
||||
| Multi-theme support | 🔴 | LOW |
|
||||
| Search | 🔴 | MEDIUM |
|
||||
| Better view | 🟢 | MEDIUM |
|
||||
| Better view, page support | 🔴 | MEDIUM |
|
||||
| Sending message etc. will use fetch API | 🟢 | HIGH |
|
||||
|
||||
## Screenshot
|
||||
|
|
4
index.js
4
index.js
|
@ -18,6 +18,10 @@ app.use(express.json());
|
|||
app.use(async (req, res, next) => {
|
||||
res.error = (type, error) => res.status(type).render("error", { type, error });
|
||||
req.user = await UserModel.get(req.session.userid);
|
||||
if (user.deleted) {
|
||||
req.session.destroy();
|
||||
return res.error(403, "Your account has been deleted.");
|
||||
}
|
||||
next();
|
||||
});
|
||||
|
||||
|
|
|
@ -16,6 +16,10 @@ const schema = new mongoose.Schema({
|
|||
})
|
||||
|
||||
schema.virtual('authorID').get(function() { return this.author?.id; });
|
||||
schema.virtual('reactCount').get(function() {
|
||||
const arr = Object.values(this.react)
|
||||
return arr.filter(Boolean).length - arr.filter(x => !x).length;
|
||||
});
|
||||
|
||||
schema.methods.takeId = async function () {
|
||||
this.id = String(await model.count() || 0);
|
||||
|
|
|
@ -8,7 +8,7 @@ export default async function request(link, method = "POST", body={}) {
|
|||
}
|
||||
}).then(res => res.json())
|
||||
|
||||
if (res.result.error) return alert(res.result.error);
|
||||
if (res.error) return alert(res.error);
|
||||
|
||||
return res;
|
||||
|
||||
|
|
|
@ -11,10 +11,9 @@ const { SecretModel, UserModel } = require("../../models")
|
|||
*/
|
||||
|
||||
app.use(async (req, res, next) => {
|
||||
res.error = (status, error) =>
|
||||
res.status(status).json({ status, result: { error } })
|
||||
res.error = (status, error) => res.status(status).json(error);
|
||||
|
||||
res.complate = result => res.status(200).json({ status: 200, result });
|
||||
res.complate = result => res.status(200).json(result);
|
||||
|
||||
if (req.user) return next();
|
||||
const { username = null, password = null } = req.headers;
|
||||
|
|
|
@ -12,7 +12,7 @@ app.get("/:id", async (req, res) => {
|
|||
|
||||
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);
|
||||
res.complate(message.toObject({ virtuals: true }));
|
||||
|
||||
})
|
||||
|
||||
|
@ -35,7 +35,7 @@ app.post("/", rateLimit({
|
|||
await message.save();
|
||||
await thread.push(message.id).save();
|
||||
|
||||
res.complate(message);
|
||||
res.complate(message.toObject({ virtuals: true }));
|
||||
|
||||
})
|
||||
app.post("/:id/react/:type", async (req, res) => {
|
||||
|
@ -50,8 +50,8 @@ app.post("/:id/react/:type", async (req, res) => {
|
|||
message.markModified("react");
|
||||
await message.save();
|
||||
|
||||
const arr = Object.values(message.react)
|
||||
res.complate(arr.filter(Boolean).length - arr.filter(x => !x).length)
|
||||
|
||||
res.complate(message.toObject({ virtuals: true }));
|
||||
} else error(res, 404, `We don't have any message with id ${req.params.id}.`);
|
||||
|
||||
|
||||
|
@ -66,7 +66,7 @@ app.post("/:id/delete", async (req, res) => {
|
|||
message.deleted = true;
|
||||
await message.save();
|
||||
|
||||
res.complate(message);
|
||||
res.complate(message.toObject({ virtuals: true }));
|
||||
|
||||
})
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ app.get("/:id", async (req, res) => {
|
|||
|
||||
const thread = await ThreadModel.get(id);
|
||||
if (thread && (req.user?.admin || !thread.deleted))
|
||||
res.complate(thread);
|
||||
res.complate(thread.toObject({ virtuals: true }));
|
||||
else
|
||||
return res.error(404, `We don't have any thread with id ${id}.`);
|
||||
|
||||
|
@ -32,7 +32,7 @@ app.get("/:id/messages/", async (req, res) => {
|
|||
|
||||
if (!messages.length) return res.error(404, "We don't have any messages in this thread.");
|
||||
|
||||
res.complate(messages);
|
||||
res.complate(messages.toObject({ virtuals: true }));
|
||||
|
||||
})
|
||||
|
||||
|
@ -48,7 +48,7 @@ app.post("/", async (req, res) => {
|
|||
await thread.push(message.id).save();
|
||||
await message.save();
|
||||
|
||||
res.complate(thread);
|
||||
res.complate(thread.toObject({ virtuals: true }));
|
||||
|
||||
});
|
||||
|
||||
|
@ -62,7 +62,7 @@ app.post("/:id/delete", async (req, res) => {
|
|||
thread.deleted = true;
|
||||
await thread.save();
|
||||
|
||||
res.complate(thread);
|
||||
res.complate(thread.toObject({ virtuals: true }));
|
||||
|
||||
})
|
||||
|
||||
|
|
|
@ -17,8 +17,8 @@ app.get("/:id", async (req, res) => {
|
|||
|
||||
if (member && (user?.admin || !member.deleted)) {
|
||||
|
||||
const message = await MessageModel.count({ authorID: id });
|
||||
const thread = await ThreadModel.count({ authorID: id });
|
||||
const message = await MessageModel.count({ "author.id": id });// this place was having problem. fixed
|
||||
const thread = await ThreadModel.count({ "author.id": id });
|
||||
res.render("user", { user, member, counts: { message, thread } })
|
||||
}
|
||||
else res.error(404, "We have not got this user.");
|
||||
|
|
|
@ -25,8 +25,8 @@
|
|||
|
||||
const response = await request("/api/users/" + e.target[0].value + "/admin");
|
||||
|
||||
if (response.result.admin)
|
||||
alert("Making admin of "+response.result.name+" is success!");
|
||||
if (response.admin)
|
||||
alert("Making admin of "+response.name+" is success!");
|
||||
|
||||
});
|
||||
|
||||
|
|
|
@ -36,9 +36,9 @@
|
|||
});
|
||||
|
||||
|
||||
if (response.result) {
|
||||
if (response) {
|
||||
alert("Thread opened");
|
||||
window.location.href = "/threads/" + response.result.id;
|
||||
window.location.href = "/threads/" + response.id;
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -60,14 +60,14 @@
|
|||
|
||||
const response = await request("/api/users/<%= member.id %>/admin");
|
||||
|
||||
if (response.result.admin)
|
||||
return alert("Making admin of " + response.result.name + " is success!");
|
||||
if (response.admin)
|
||||
return alert("Making admin of " + response.name + " is success!");
|
||||
|
||||
}
|
||||
|
||||
const response = await request("/api/users/<%= member.id %>/delete");
|
||||
|
||||
if (response.result.deleted)
|
||||
if (response.deleted)
|
||||
alert("User Deleted");
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue