randydev commited on
Commit
b1fd211
·
verified ·
1 Parent(s): 542c81d

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +9 -1
index.js CHANGED
@@ -321,6 +321,7 @@ app.post('/api/v2/key/generate-key', authenticateApiKey, apiLimiter, async (req,
321
  app.post("/api/v1/key/revoked-key", authenticateApiKey, apiLimiter, async (req, res) => {
322
  const dbClient = new Database("AkenoXJs");
323
  const collection = dbClient.collection("api_keys");
 
324
 
325
  try {
326
  const userIdString = req.query.user_id;
@@ -331,6 +332,11 @@ app.post("/api/v1/key/revoked-key", authenticateApiKey, apiLimiter, async (req,
331
  return res.status(400).json({ error: "Invalid or missing user_id" });
332
  }
333
 
 
 
 
 
 
334
  const existingUser = await collection.findOne({ owner: userIdNumber });
335
 
336
  if (!existingUser) {
@@ -356,7 +362,9 @@ app.post("/api/v1/key/revoked-key", authenticateApiKey, apiLimiter, async (req,
356
  message: "API key successfully revoked and regenerated",
357
  apiKey: newKey,
358
  createdAt: new Date(),
359
- owner: userIdNumber
 
 
360
  });
361
  } else {
362
  res.status(500).json({ error: "Failed to update API key" });
 
321
  app.post("/api/v1/key/revoked-key", authenticateApiKey, apiLimiter, async (req, res) => {
322
  const dbClient = new Database("AkenoXJs");
323
  const collection = dbClient.collection("api_keys");
324
+ const bannedCollection = dbClient.collection("banned_users");
325
 
326
  try {
327
  const userIdString = req.query.user_id;
 
332
  return res.status(400).json({ error: "Invalid or missing user_id" });
333
  }
334
 
335
+ const isBanned = await bannedCollection.findOne({ user_id: userIdNumber });
336
+ if (isBanned) {
337
+ return res.status(200).json({ message: "You are permanently banned from creating API keys", is_deleted: true });
338
+ }
339
+
340
  const existingUser = await collection.findOne({ owner: userIdNumber });
341
 
342
  if (!existingUser) {
 
362
  message: "API key successfully revoked and regenerated",
363
  apiKey: newKey,
364
  createdAt: new Date(),
365
+ owner: userIdNumber,
366
+ is_deleted: false,
367
+ is_banned: false
368
  });
369
  } else {
370
  res.status(500).json({ error: "Failed to update API key" });