Revert "IP based rate limit"
Browse filesThis reverts commit 87c693736f128927291f8b396dba85fa992539ae.
src/routes/conversation/[id]/+server.ts
CHANGED
|
@@ -46,21 +46,10 @@ export async function POST({ request, fetch, locals, params, getClientAddress })
|
|
| 46 |
throw error(429, "Exceeded number of messages before login");
|
| 47 |
}
|
| 48 |
|
| 49 |
-
|
| 50 |
-
let nEvents = 0;
|
| 51 |
-
if (locals.user?._id) {
|
| 52 |
-
// if logged in do rate limiting based on user id
|
| 53 |
-
nEvents = await collections.messageEvents.countDocuments({ userId });
|
| 54 |
-
} else {
|
| 55 |
-
// do rate limiting based on session id but also ip address
|
| 56 |
-
const nEventsIp = await collections.messageEvents.countDocuments({ ip: getClientAddress() });
|
| 57 |
-
const nEventsSession = await collections.messageEvents.countDocuments({ userId });
|
| 58 |
-
nEvents = Math.max(nEventsIp, nEventsSession);
|
| 59 |
-
}
|
| 60 |
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
}
|
| 64 |
}
|
| 65 |
|
| 66 |
const model = models.find((m) => m.id === conv.model);
|
|
|
|
| 46 |
throw error(429, "Exceeded number of messages before login");
|
| 47 |
}
|
| 48 |
|
| 49 |
+
const nEvents = await collections.messageEvents.countDocuments({ userId });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
+
if (RATE_LIMIT != "" && nEvents > parseInt(RATE_LIMIT)) {
|
| 52 |
+
throw error(429, ERROR_MESSAGES.rateLimited);
|
|
|
|
| 53 |
}
|
| 54 |
|
| 55 |
const model = models.find((m) => m.id === conv.model);
|