mirror of
https://github.com/Akif9748/akf-forum.git
synced 2024-11-26 21:30:42 +03:00
Timeout removed
This commit is contained in:
parent
0144741a97
commit
11d79cd7ad
9 changed files with 65 additions and 78 deletions
|
@ -17,6 +17,7 @@ module.exports = class Message {
|
||||||
|
|
||||||
}
|
}
|
||||||
async getById(id = this.id) {
|
async getById(id = this.id) {
|
||||||
|
try {
|
||||||
this.id = Number(id);
|
this.id = Number(id);
|
||||||
|
|
||||||
const message = await MessageModel.findOne({ id });
|
const message = await MessageModel.findOne({ id });
|
||||||
|
@ -32,6 +33,9 @@ module.exports = class Message {
|
||||||
this.edited = edited;
|
this.edited = edited;
|
||||||
this.react = react;
|
this.react = react;
|
||||||
return this;
|
return this;
|
||||||
|
} catch (e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async takeId() {
|
async takeId() {
|
||||||
|
|
|
@ -17,6 +17,7 @@ module.exports = class Thread {
|
||||||
}
|
}
|
||||||
|
|
||||||
async getById(id = this.id) {
|
async getById(id = this.id) {
|
||||||
|
try {
|
||||||
this.id = Number(id);
|
this.id = Number(id);
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,6 +33,9 @@ module.exports = class Thread {
|
||||||
this.deleted = deleted;
|
this.deleted = deleted;
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
} catch (e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
push(messageID) {
|
push(messageID) {
|
||||||
|
|
|
@ -14,6 +14,7 @@ module.exports = class User {
|
||||||
}
|
}
|
||||||
|
|
||||||
async getById(id = this.id) {
|
async getById(id = this.id) {
|
||||||
|
try {
|
||||||
this.id = Number(id);
|
this.id = Number(id);
|
||||||
const user = await UserModel.findOne({ id });
|
const user = await UserModel.findOne({ id });
|
||||||
if (!user) return null;
|
if (!user) return null;
|
||||||
|
@ -25,12 +26,16 @@ module.exports = class User {
|
||||||
this.admin = admin;
|
this.admin = admin;
|
||||||
this.deleted = deleted;
|
this.deleted = deleted;
|
||||||
return this;
|
return this;
|
||||||
|
} catch (e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getByName(Name = this.name) {
|
async getByName(Name = this.name) {
|
||||||
|
try {
|
||||||
const user = await UserModel.findOne({ name: Name });
|
const user = await UserModel.findOne({ name: Name });
|
||||||
|
|
||||||
if (!user) return null;
|
if (!user) return null;
|
||||||
|
|
||||||
const { id, name = "guest", avatar = "/images/guest.png", time = Date.now(), admin = false, deleted = false } = user;
|
const { id, name = "guest", avatar = "/images/guest.png", time = Date.now(), admin = false, deleted = false } = user;
|
||||||
|
@ -42,6 +47,10 @@ module.exports = class User {
|
||||||
this.admin = admin;
|
this.admin = admin;
|
||||||
this.deleted = deleted;
|
this.deleted = deleted;
|
||||||
return this;
|
return this;
|
||||||
|
} catch (e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
1
index.js
1
index.js
|
@ -15,7 +15,6 @@ app.use(express.static("public"));
|
||||||
app.set("view engine", "ejs");
|
app.set("view engine", "ejs");
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
app.use(require("./middlewares/user"));
|
app.use(require("./middlewares/user"));
|
||||||
app.use(require("./middlewares/timeout"));
|
|
||||||
|
|
||||||
for (const file of fs.readdirSync("./routes"))
|
for (const file of fs.readdirSync("./routes"))
|
||||||
app.use("/" + file.replace(".js", ""), require(`./routes/${file}`));
|
app.use("/" + file.replace(".js", ""), require(`./routes/${file}`));
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
const { TimeoutModel } = require("../models");
|
|
||||||
module.exports = async (req, res, next) => {
|
|
||||||
if (!req.user || req.user.admin) return next();
|
|
||||||
|
|
||||||
const timeout = await TimeoutModel.findOne({ id: req.user.id }) || new TimeoutModel({ until: Date.now() - 1000, id: req.user.id });
|
|
||||||
|
|
||||||
req.timeout = timeout;
|
|
||||||
|
|
||||||
if (timeout.until > Date.now())
|
|
||||||
req.ratelimit = true;
|
|
||||||
|
|
||||||
|
|
||||||
next();
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,8 +0,0 @@
|
||||||
const { Schema, model } = require("mongoose")
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = model('timeout', new Schema({
|
|
||||||
id: { type: Number, unique: true },
|
|
||||||
until: Number
|
|
||||||
|
|
||||||
}))
|
|
|
@ -1,7 +1,6 @@
|
||||||
const UserModel = require("./User"),
|
const UserModel = require("./User"),
|
||||||
MessageModel = require("./Message"),
|
MessageModel = require("./Message"),
|
||||||
ThreadModel = require("./Thread"),
|
ThreadModel = require("./Thread"),
|
||||||
SecretModel = require("./Secret"),
|
SecretModel = require("./Secret");
|
||||||
TimeoutModel = require("./Timeout");
|
|
||||||
|
|
||||||
module.exports = { UserModel, MessageModel, ThreadModel, SecretModel, TimeoutModel };
|
module.exports = { UserModel, MessageModel, ThreadModel, SecretModel };
|
|
@ -17,7 +17,6 @@ app.use(require("../middlewares/login"));
|
||||||
|
|
||||||
|
|
||||||
app.post("/", async (req, res) => {
|
app.post("/", async (req, res) => {
|
||||||
// if (req.ratelimit) return error(res, 429, "Wait until " + new Date(req.timeout.until).toLocaleTimeString("tr") + ", you are too quick for send.")
|
|
||||||
|
|
||||||
const thread = await new Thread().getById(req.body.threadID);
|
const thread = await new Thread().getById(req.body.threadID);
|
||||||
if (thread) {
|
if (thread) {
|
||||||
|
@ -26,9 +25,6 @@ app.post("/", async (req, res) => {
|
||||||
thread.push(message.id);
|
thread.push(message.id);
|
||||||
thread.write();
|
thread.write();
|
||||||
|
|
||||||
// req.timeout.until += 1000 * 30;
|
|
||||||
// await req.timeout.save()
|
|
||||||
|
|
||||||
res.redirect('/threads/' + req.body.threadID);
|
res.redirect('/threads/' + req.body.threadID);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,6 @@ app.use(require("../middlewares/login"));
|
||||||
|
|
||||||
|
|
||||||
app.post("/", async (req, res) => {
|
app.post("/", async (req, res) => {
|
||||||
// if (req.ratelimit) return error(res, 429, "Wait until " + new Date(req.timeout.until).toLocaleTimeString("tr") + ", you are too quick for send.")
|
|
||||||
|
|
||||||
const { title = null, content = null } = req.body;
|
const { title = null, content = null } = req.body;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue