Update plugins/antiban.js
Browse files- plugins/antiban.js +47 -0
plugins/antiban.js
CHANGED
@@ -59,6 +59,53 @@ AntibanRoutes.post("/api/v1/user/ban-user", authenticateApiKey, apiLimiter, asyn
|
|
59 |
}
|
60 |
});
|
61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
AntibanRoutes.get("/api/v1/user/check-ban", authenticateApiKey, async (req, res) => {
|
63 |
const dbClient = new Database("AkenoXJs");
|
64 |
const collection = dbClient.collection("ban_users");
|
|
|
59 |
}
|
60 |
});
|
61 |
|
62 |
+
AntibanRoutes.get("/api/v1/user/anti-broadcast", authenticateApiKey, async (req, res) => {
|
63 |
+
const dbClient = new Database("AkenoXJs");
|
64 |
+
const collection = dbClient.collection("users_broadcast");
|
65 |
+
const collectionKey = dbClient.collection("api_keys");
|
66 |
+
try {
|
67 |
+
const apiKey = req.headers["x-api-key"];
|
68 |
+
const userIdString = req.query.user_id;
|
69 |
+
const userIdNumber = Number(userIdString);
|
70 |
+
|
71 |
+
if (!apiKey) {
|
72 |
+
return res.status(400).json({ error: "Missing API key in headers" });
|
73 |
+
}
|
74 |
+
|
75 |
+
if (isNaN(userIdNumber)) {
|
76 |
+
return res.status(400).json({ error: "Invalid or missing user_id" });
|
77 |
+
}
|
78 |
+
|
79 |
+
const existingUserKey = await collectionKey.findOne({ key: apiKey });
|
80 |
+
|
81 |
+
if (!existingUserKey) {
|
82 |
+
return res.status(401).json({ message: "API key not found" });
|
83 |
+
}
|
84 |
+
|
85 |
+
if (existingUserKey.owner === userIdNumber) {
|
86 |
+
return res.status(200).json({
|
87 |
+
message: `User ${userIdNumber} cannot be broadcast because they created the API key`,
|
88 |
+
is_broadcast: false
|
89 |
+
});
|
90 |
+
}
|
91 |
+
|
92 |
+
const existingGikes = await collection.findOne({ user_gikes: userIdNumber });
|
93 |
+
if (existingGikes) {
|
94 |
+
return res.status(200).json({ message: `User ${userIdNumber} is already broadcast`, is_broadcast: true });
|
95 |
+
}
|
96 |
+
|
97 |
+
await collection.updateOne(
|
98 |
+
{ key: existingUserKey.key },
|
99 |
+
{ $addToSet: { user_gikes: userIdNumber }, $set: { updatedAt: new Date(), owner: existingUserKey.owner, is_broadcast: true} },
|
100 |
+
{ upsert: true }
|
101 |
+
);
|
102 |
+
res.json({ message: `User ${userIdNumber} successfully broadcast`, is_broadcast: true });
|
103 |
+
|
104 |
+
} catch (error) {
|
105 |
+
res.status(500).json({ error: `Internal server error: ${error.message}` });
|
106 |
+
}
|
107 |
+
});
|
108 |
+
|
109 |
AntibanRoutes.get("/api/v1/user/check-ban", authenticateApiKey, async (req, res) => {
|
110 |
const dbClient = new Database("AkenoXJs");
|
111 |
const collection = dbClient.collection("ban_users");
|