summary refs log tree commit diff
path: root/api/src/middlewares
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-08-24 16:35:04 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-08-24 16:35:04 +0200
commitef4d4a318176c3e572adc17427a8b8c728a618ab (patch)
treed95fedbf18b7b7438613b08b72eb30fa5fca8921 /api/src/middlewares
parent:sparkles: typeorm entities (diff)
downloadserver-ef4d4a318176c3e572adc17427a8b8c728a618ab.tar.xz
:construction: api
Diffstat (limited to 'api/src/middlewares')
-rw-r--r--api/src/middlewares/RateLimit.ts6
1 files changed, 3 insertions, 3 deletions
diff --git a/api/src/middlewares/RateLimit.ts b/api/src/middlewares/RateLimit.ts
index acf92606..9601dad3 100644
--- a/api/src/middlewares/RateLimit.ts
+++ b/api/src/middlewares/RateLimit.ts
@@ -72,7 +72,7 @@ export default function RateLimit(opts: {
 				offender.expires_at = new Date(Date.now() + opts.window * 1000);
 				offender.blocked = false;
 				// mongodb ttl didn't update yet -> manually update/delete
-				db.collection("ratelimits").updateOne({ id: bucket_id, user_id }, { $set: offender });
+				db.collection("ratelimits").update({ id: bucket_id, user_id }, { $set: offender });
 				Cache.delete(user_id + bucket_id);
 			}
 		}
@@ -132,7 +132,7 @@ export async function initRateLimits(app: Router) {
 
 async function hitRoute(opts: { user_id: string; bucket_id: string; max_hits: number; window: number }) {
 	const filter = { id: opts.bucket_id, user_id: opts.user_id };
-	const { value } = await db.collection("ratelimits").findOneAndUpdate(
+	const { value } = await db.collection("ratelimits").findOneOrFailAndUpdate(
 		filter,
 		{
 			$setOnInsert: {
@@ -158,7 +158,7 @@ async function hitRoute(opts: { user_id: string; bucket_id: string; max_hits: nu
 			event: EventRateLimit,
 			data: value
 		});
-		await db.collection("ratelimits").updateOne(filter, { $set: { blocked: true } });
+		await db.collection("ratelimits").update(filter, { $set: { blocked: true } });
 	} else {
 		Cache.delete(opts.user_id);
 	}