mirror of
https://github.com/Akif9748/akf-forum.git
synced 2024-11-26 13:20:41 +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 |
|
| auto-scroll | 🟢 | LOW |
|
||||||
| Multi-theme support | 🔴 | LOW |
|
| Multi-theme support | 🔴 | LOW |
|
||||||
| Search | 🔴 | MEDIUM |
|
| Search | 🔴 | MEDIUM |
|
||||||
| Better view | 🟢 | MEDIUM |
|
| Better view, page support | 🔴 | MEDIUM |
|
||||||
| Sending message etc. will use fetch API | 🟢 | HIGH |
|
| Sending message etc. will use fetch API | 🟢 | HIGH |
|
||||||
|
|
||||||
## Screenshot
|
## Screenshot
|
||||||
|
|
4
index.js
4
index.js
|
@ -18,6 +18,10 @@ app.use(express.json());
|
||||||
app.use(async (req, res, next) => {
|
app.use(async (req, res, next) => {
|
||||||
res.error = (type, error) => res.status(type).render("error", { type, error });
|
res.error = (type, error) => res.status(type).render("error", { type, error });
|
||||||
req.user = await UserModel.get(req.session.userid);
|
req.user = await UserModel.get(req.session.userid);
|
||||||
|
if (user.deleted) {
|
||||||
|
req.session.destroy();
|
||||||
|
return res.error(403, "Your account has been deleted.");
|
||||||
|
}
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,10 @@ const schema = new mongoose.Schema({
|
||||||
})
|
})
|
||||||
|
|
||||||
schema.virtual('authorID').get(function() { return this.author?.id; });
|
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 () {
|
schema.methods.takeId = async function () {
|
||||||
this.id = String(await model.count() || 0);
|
this.id = String(await model.count() || 0);
|
||||||
|
|
|
@ -8,7 +8,7 @@ export default async function request(link, method = "POST", body={}) {
|
||||||
}
|
}
|
||||||
}).then(res => res.json())
|
}).then(res => res.json())
|
||||||
|
|
||||||
if (res.result.error) return alert(res.result.error);
|
if (res.error) return alert(res.error);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
|
|
|
@ -11,10 +11,9 @@ const { SecretModel, UserModel } = require("../../models")
|
||||||
*/
|
*/
|
||||||
|
|
||||||
app.use(async (req, res, next) => {
|
app.use(async (req, res, next) => {
|
||||||
res.error = (status, error) =>
|
res.error = (status, error) => res.status(status).json(error);
|
||||||
res.status(status).json({ status, result: { error } })
|
|
||||||
|
|
||||||
res.complate = result => res.status(200).json({ status: 200, result });
|
res.complate = result => res.status(200).json(result);
|
||||||
|
|
||||||
if (req.user) return next();
|
if (req.user) return next();
|
||||||
const { username = null, password = null } = req.headers;
|
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}.`);
|
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 message.save();
|
||||||
await thread.push(message.id).save();
|
await thread.push(message.id).save();
|
||||||
|
|
||||||
res.complate(message);
|
res.complate(message.toObject({ virtuals: true }));
|
||||||
|
|
||||||
})
|
})
|
||||||
app.post("/:id/react/:type", async (req, res) => {
|
app.post("/:id/react/:type", async (req, res) => {
|
||||||
|
@ -50,8 +50,8 @@ app.post("/:id/react/:type", async (req, res) => {
|
||||||
message.markModified("react");
|
message.markModified("react");
|
||||||
await message.save();
|
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}.`);
|
} 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;
|
message.deleted = true;
|
||||||
await message.save();
|
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);
|
const thread = await ThreadModel.get(id);
|
||||||
if (thread && (req.user?.admin || !thread.deleted))
|
if (thread && (req.user?.admin || !thread.deleted))
|
||||||
res.complate(thread);
|
res.complate(thread.toObject({ virtuals: true }));
|
||||||
else
|
else
|
||||||
return res.error(404, `We don't have any thread with id ${id}.`);
|
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.");
|
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 thread.push(message.id).save();
|
||||||
await message.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;
|
thread.deleted = true;
|
||||||
await thread.save();
|
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)) {
|
if (member && (user?.admin || !member.deleted)) {
|
||||||
|
|
||||||
const message = await MessageModel.count({ authorID: id });
|
const message = await MessageModel.count({ "author.id": id });// this place was having problem. fixed
|
||||||
const thread = await ThreadModel.count({ authorID: id });
|
const thread = await ThreadModel.count({ "author.id": id });
|
||||||
res.render("user", { user, member, counts: { message, thread } })
|
res.render("user", { user, member, counts: { message, thread } })
|
||||||
}
|
}
|
||||||
else res.error(404, "We have not got this user.");
|
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");
|
const response = await request("/api/users/" + e.target[0].value + "/admin");
|
||||||
|
|
||||||
if (response.result.admin)
|
if (response.admin)
|
||||||
alert("Making admin of "+response.result.name+" is success!");
|
alert("Making admin of "+response.name+" is success!");
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -36,9 +36,9 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
if (response.result) {
|
if (response) {
|
||||||
alert("Thread opened");
|
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");
|
const response = await request("/api/users/<%= member.id %>/admin");
|
||||||
|
|
||||||
if (response.result.admin)
|
if (response.admin)
|
||||||
return alert("Making admin of " + response.result.name + " is success!");
|
return alert("Making admin of " + response.name + " is success!");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await request("/api/users/<%= member.id %>/delete");
|
const response = await request("/api/users/<%= member.id %>/delete");
|
||||||
|
|
||||||
if (response.result.deleted)
|
if (response.deleted)
|
||||||
alert("User Deleted");
|
alert("User Deleted");
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue