Spaces:
Running
Running
Add createdAt filter on messageEvents (#1256)
Browse files
src/routes/conversation/[id]/+server.ts
CHANGED
@@ -102,8 +102,14 @@ export async function POST({ request, locals, params, getClientAddress }) {
|
|
102 |
if (usageLimits?.messagesPerMinute) {
|
103 |
// check if the user is rate limited
|
104 |
const nEvents = Math.max(
|
105 |
-
await collections.messageEvents.countDocuments({
|
106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
);
|
108 |
if (nEvents > usageLimits.messagesPerMinute) {
|
109 |
throw error(429, ERROR_MESSAGES.rateLimited);
|
|
|
102 |
if (usageLimits?.messagesPerMinute) {
|
103 |
// check if the user is rate limited
|
104 |
const nEvents = Math.max(
|
105 |
+
await collections.messageEvents.countDocuments({
|
106 |
+
userId,
|
107 |
+
createdAt: { $gte: new Date(Date.now() - 60_000) },
|
108 |
+
}),
|
109 |
+
await collections.messageEvents.countDocuments({
|
110 |
+
ip: getClientAddress(),
|
111 |
+
createdAt: { $gte: new Date(Date.now() - 60_000) },
|
112 |
+
})
|
113 |
);
|
114 |
if (nEvents > usageLimits.messagesPerMinute) {
|
115 |
throw error(429, ERROR_MESSAGES.rateLimited);
|