Update index.js
Browse files
index.js
CHANGED
@@ -384,22 +384,17 @@ app.post("/api/v1/key/api-key-ban", authenticateApiKey, apiLimiter, async (req,
|
|
384 |
const userIdString = req.query.user_id;
|
385 |
const userIdNumber = Number(userIdString);
|
386 |
|
387 |
-
if (isNaN(userIdNumber)) {
|
388 |
-
return res.status(400).json({ error: "Invalid or missing user_id" });
|
389 |
-
}
|
390 |
-
|
391 |
-
if (userIdNumber === 0) {
|
392 |
return res.status(400).json({ error: "Invalid user_id" });
|
393 |
}
|
394 |
|
395 |
if (userIdNumber === 6477856957) {
|
396 |
-
return res.status(400).json({ error: "
|
397 |
}
|
398 |
-
|
399 |
-
const existingUserTwo = await ApiKey.findOne({ owner: userIdNumber });
|
400 |
const existingUser = await collection.findOne({ owner: userIdNumber });
|
|
|
401 |
|
402 |
-
if (!existingUser
|
403 |
const userDocument = {
|
404 |
key: "banned",
|
405 |
createdAt: new Date(),
|
@@ -408,6 +403,7 @@ app.post("/api/v1/key/api-key-ban", authenticateApiKey, apiLimiter, async (req,
|
|
408 |
is_banned: true,
|
409 |
username: null,
|
410 |
};
|
|
|
411 |
const userDocumentTwo = new ApiKey({
|
412 |
key: "banned",
|
413 |
createdAt: new Date(),
|
@@ -415,39 +411,41 @@ app.post("/api/v1/key/api-key-ban", authenticateApiKey, apiLimiter, async (req,
|
|
415 |
owner: userIdNumber,
|
416 |
type: "premium",
|
417 |
is_banned: true,
|
418 |
-
email: null
|
419 |
});
|
420 |
-
|
421 |
await collection.insertOne(userDocument);
|
|
|
|
|
422 |
return res.status(200).json({
|
423 |
message: "API key successfully banned",
|
424 |
owner: userIdNumber
|
425 |
});
|
426 |
}
|
427 |
|
428 |
-
if (existingUser.is_banned
|
429 |
return res.status(200).json({ message: "API key is already banned" });
|
430 |
}
|
431 |
|
432 |
-
const resultTwo = await ApiKey.updateOne(
|
433 |
-
{ owner: userIdNumber },
|
434 |
-
{ $set: { is_banned: true } },
|
435 |
-
{ upsert: false }
|
436 |
-
);
|
437 |
-
|
438 |
const result = await collection.updateOne(
|
439 |
{ owner: userIdNumber },
|
440 |
{ $set: { is_banned: true } },
|
441 |
{ upsert: false }
|
442 |
);
|
443 |
|
444 |
-
|
445 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
446 |
message: "API key successfully banned",
|
447 |
owner: userIdNumber
|
448 |
});
|
449 |
} else {
|
450 |
-
res.status(500).json({ error: "Failed to ban API key" });
|
451 |
}
|
452 |
|
453 |
} catch (err) {
|
|
|
384 |
const userIdString = req.query.user_id;
|
385 |
const userIdNumber = Number(userIdString);
|
386 |
|
387 |
+
if (isNaN(userIdNumber) || userIdNumber === 0) {
|
|
|
|
|
|
|
|
|
388 |
return res.status(400).json({ error: "Invalid user_id" });
|
389 |
}
|
390 |
|
391 |
if (userIdNumber === 6477856957) {
|
392 |
+
return res.status(400).json({ error: "Sorry, only the developer can perform this action." });
|
393 |
}
|
|
|
|
|
394 |
const existingUser = await collection.findOne({ owner: userIdNumber });
|
395 |
+
const existingUserTwo = await ApiKey.findOne({ owner: userIdNumber });
|
396 |
|
397 |
+
if (!existingUser && !existingUserTwo) {
|
398 |
const userDocument = {
|
399 |
key: "banned",
|
400 |
createdAt: new Date(),
|
|
|
403 |
is_banned: true,
|
404 |
username: null,
|
405 |
};
|
406 |
+
|
407 |
const userDocumentTwo = new ApiKey({
|
408 |
key: "banned",
|
409 |
createdAt: new Date(),
|
|
|
411 |
owner: userIdNumber,
|
412 |
type: "premium",
|
413 |
is_banned: true,
|
414 |
+
email: null,
|
415 |
});
|
416 |
+
|
417 |
await collection.insertOne(userDocument);
|
418 |
+
await userDocumentTwo.save();
|
419 |
+
|
420 |
return res.status(200).json({
|
421 |
message: "API key successfully banned",
|
422 |
owner: userIdNumber
|
423 |
});
|
424 |
}
|
425 |
|
426 |
+
if ((existingUser && existingUser.is_banned) || (existingUserTwo && existingUserTwo.is_banned)) {
|
427 |
return res.status(200).json({ message: "API key is already banned" });
|
428 |
}
|
429 |
|
|
|
|
|
|
|
|
|
|
|
|
|
430 |
const result = await collection.updateOne(
|
431 |
{ owner: userIdNumber },
|
432 |
{ $set: { is_banned: true } },
|
433 |
{ upsert: false }
|
434 |
);
|
435 |
|
436 |
+
const resultTwo = await ApiKey.updateOne(
|
437 |
+
{ owner: userIdNumber },
|
438 |
+
{ $set: { is_banned: true } },
|
439 |
+
{ upsert: false }
|
440 |
+
);
|
441 |
+
|
442 |
+
if (result.matchedCount > 0 || resultTwo.matchedCount > 0) {
|
443 |
+
return res.status(200).json({
|
444 |
message: "API key successfully banned",
|
445 |
owner: userIdNumber
|
446 |
});
|
447 |
} else {
|
448 |
+
return res.status(500).json({ error: "Failed to ban API key" });
|
449 |
}
|
450 |
|
451 |
} catch (err) {
|