feat: ban-user command (#1121)

* feat: ban-user command

* clean up code

* added duration

* fix(package-lock) revert commit
This commit is contained in:
Marco Beretta 2023-11-04 16:38:58 +01:00 committed by GitHub
parent 34148885b7
commit a7b5639da1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 102 additions and 1 deletions

View file

@ -47,7 +47,7 @@ const banViolation = async (req, res, errorMessage) => {
res.clearCookie('refreshToken');
const banLogs = getLogStores('ban');
const duration = banLogs.opts.ttl;
const duration = errorMessage.duration || banLogs.opts.ttl;
if (duration <= 0) {
return;
@ -55,6 +55,7 @@ const banViolation = async (req, res, errorMessage) => {
req.ip = removePorts(req);
console.log(`[BAN] Banning user ${user_id} @ ${req.ip} for ${duration / 1000 / 60} minutes`);
const expiresAt = Date.now() + duration;
await banLogs.set(user_id, { type, violation_count, duration, expiresAt });
await banLogs.set(req.ip, { type, user_id, violation_count, duration, expiresAt });