From 7547344fcbb28cb6fe04245317124ea6d53c92f7 Mon Sep 17 00:00:00 2001 From: sirpiglr <49359077-sirpiglr@users.noreply.replit.com> Date: Tue, 16 Dec 2025 00:14:02 +0000 Subject: [PATCH] Fix type mismatch in chatbot rate limiting logic Adjusted the `chatRateLimits` Map in `server/routes.ts` to use string keys (userId) instead of number keys, resolving a TypeScript type error and ensuring correct rate limiting for the chatbot API. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 279f1558-c0e3-40e4-8217-be7e9f4c6eca Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: 6fd6dbdc-a507-4c93-8855-b3ae8007f31c Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/b984cb14-1d19-4944-922b-bc79e821ed35/279f1558-c0e3-40e4-8217-be7e9f4c6eca/e4kDtnh Replit-Helium-Checkpoint-Created: true --- server/routes.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/server/routes.ts b/server/routes.ts index a144119..07a5910 100644 --- a/server/routes.ts +++ b/server/routes.ts @@ -299,7 +299,7 @@ export async function registerRoutes( // ========== CHATBOT API (Auth + Rate limited) ========== - const chatRateLimits = new Map(); + const chatRateLimits = new Map(); app.post("/api/chat", requireAuth, async (req, res) => { try { @@ -308,8 +308,9 @@ export async function registerRoutes( return res.status(401).json({ error: "Authentication required" }); } + const userKey = String(userId); const now = Date.now(); - const rateLimit = chatRateLimits.get(userId); + const rateLimit = chatRateLimits.get(userKey); if (rateLimit) { if (now < rateLimit.resetTime) { @@ -318,10 +319,10 @@ export async function registerRoutes( } rateLimit.count++; } else { - chatRateLimits.set(userId, { count: 1, resetTime: now + 60000 }); + chatRateLimits.set(userKey, { count: 1, resetTime: now + 60000 }); } } else { - chatRateLimits.set(userId, { count: 1, resetTime: now + 60000 }); + chatRateLimits.set(userKey, { count: 1, resetTime: now + 60000 }); } const { message, history } = req.body;