Timeout removed

This commit is contained in:
Akif9748 2022-04-06 22:21:50 +03:00
parent 0144741a97
commit 11d79cd7ad
9 changed files with 65 additions and 78 deletions

View file

@ -17,6 +17,7 @@ module.exports = class Message {
}
async getById(id = this.id) {
try {
this.id = Number(id);
const message = await MessageModel.findOne({ id });
@ -32,6 +33,9 @@ module.exports = class Message {
this.edited = edited;
this.react = react;
return this;
} catch (e) {
return null;
}
}
async takeId() {

View file

@ -17,6 +17,7 @@ module.exports = class Thread {
}
async getById(id = this.id) {
try {
this.id = Number(id);
@ -32,6 +33,9 @@ module.exports = class Thread {
this.deleted = deleted;
return this;
} catch (e) {
return null;
}
}
push(messageID) {

View file

@ -14,6 +14,7 @@ module.exports = class User {
}
async getById(id = this.id) {
try {
this.id = Number(id);
const user = await UserModel.findOne({ id });
if (!user) return null;
@ -25,12 +26,16 @@ module.exports = class User {
this.admin = admin;
this.deleted = deleted;
return this;
} catch (e) {
return null;
}
}
async getByName(Name = this.name) {
try {
const user = await UserModel.findOne({ name: Name });
if (!user) return null;
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.deleted = deleted;
return this;
} catch (e) {
return null;
}
}

View file

@ -15,7 +15,6 @@ app.use(express.static("public"));
app.set("view engine", "ejs");
app.use(express.json());
app.use(require("./middlewares/user"));
app.use(require("./middlewares/timeout"));
for (const file of fs.readdirSync("./routes"))
app.use("/" + file.replace(".js", ""), require(`./routes/${file}`));

View 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();
}

View file

@ -1,8 +0,0 @@
const { Schema, model } = require("mongoose")
module.exports = model('timeout', new Schema({
id: { type: Number, unique: true },
until: Number
}))

View file

@ -1,7 +1,6 @@
const UserModel = require("./User"),
MessageModel = require("./Message"),
ThreadModel = require("./Thread"),
SecretModel = require("./Secret"),
TimeoutModel = require("./Timeout");
SecretModel = require("./Secret");
module.exports = { UserModel, MessageModel, ThreadModel, SecretModel, TimeoutModel };
module.exports = { UserModel, MessageModel, ThreadModel, SecretModel };

View file

@ -17,7 +17,6 @@ app.use(require("../middlewares/login"));
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);
if (thread) {
@ -26,9 +25,6 @@ app.post("/", async (req, res) => {
thread.push(message.id);
thread.write();
// req.timeout.until += 1000 * 30;
// await req.timeout.save()
res.redirect('/threads/' + req.body.threadID);
}

View file

@ -50,7 +50,6 @@ app.use(require("../middlewares/login"));
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;