mirror of
https://github.com/AeThex-Corporation/AeThex-OS.git
synced 2026-04-17 22:27:19 +00:00
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
This commit is contained in:
parent
943a55fa41
commit
7547344fcb
1 changed files with 5 additions and 4 deletions
|
|
@ -299,7 +299,7 @@ export async function registerRoutes(
|
|||
|
||||
// ========== CHATBOT API (Auth + Rate limited) ==========
|
||||
|
||||
const chatRateLimits = new Map<number, { count: number; resetTime: number }>();
|
||||
const chatRateLimits = new Map<string, { count: number; resetTime: number }>();
|
||||
|
||||
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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue