Update plugins/antiban.js
Browse files- plugins/antiban.js +28 -12
plugins/antiban.js
CHANGED
@@ -63,42 +63,58 @@ AntibanRoutes.post("/api/v1/user/anti-broadcast", authenticateApiKey, async (req
|
|
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 |
-
|
88 |
-
|
89 |
});
|
90 |
}
|
91 |
|
92 |
-
const
|
93 |
-
if (
|
94 |
-
return res.status(200).json({ message: `User ${userIdNumber} is already
|
|
|
|
|
|
|
|
|
95 |
}
|
96 |
|
97 |
await collection.updateOne(
|
98 |
-
{
|
99 |
-
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
{ upsert: true }
|
101 |
);
|
|
|
102 |
res.json({ message: `User ${userIdNumber} successfully broadcast`, is_broadcast: true });
|
103 |
|
104 |
} catch (error) {
|
|
|
63 |
const dbClient = new Database("AkenoXJs");
|
64 |
const collection = dbClient.collection("users_broadcast");
|
65 |
const collectionKey = dbClient.collection("api_keys");
|
66 |
+
|
67 |
try {
|
68 |
const apiKey = req.headers["x-api-key"];
|
69 |
const userIdString = req.query.user_id;
|
70 |
+
const WorldString = req.query.text;
|
71 |
const userIdNumber = Number(userIdString);
|
72 |
+
|
73 |
if (!apiKey) {
|
74 |
return res.status(400).json({ error: "Missing API key in headers" });
|
75 |
}
|
76 |
+
if (!WorldString) {
|
77 |
+
return res.status(400).json({ error: "Missing params: text" });
|
78 |
+
}
|
79 |
if (isNaN(userIdNumber)) {
|
80 |
return res.status(400).json({ error: "Invalid or missing user_id" });
|
81 |
}
|
82 |
+
|
83 |
const existingUserKey = await collectionKey.findOne({ key: apiKey });
|
84 |
+
|
85 |
if (!existingUserKey) {
|
86 |
return res.status(401).json({ message: "API key not found" });
|
87 |
}
|
88 |
+
|
89 |
if (existingUserKey.owner === userIdNumber) {
|
90 |
return res.status(200).json({
|
91 |
+
message: `User ${userIdNumber} cannot be broadcast because they created the API key`,
|
92 |
+
is_broadcast: false
|
93 |
});
|
94 |
}
|
95 |
|
96 |
+
const existingBroadcast = await collection.findOne({ user_id: userIdNumber });
|
97 |
+
if (existingBroadcast) {
|
98 |
+
return res.status(200).json({ message: `User ${userIdNumber} is already broadcasting`, is_broadcast: true });
|
99 |
+
}
|
100 |
+
|
101 |
+
if (WorldString.length > 3096) {
|
102 |
+
return res.status(400).json({ message: `User ${userIdNumber} is sending a spam broadcast`, is_broadcast: true });
|
103 |
}
|
104 |
|
105 |
await collection.updateOne(
|
106 |
+
{ user_id: userIdNumber },
|
107 |
+
{
|
108 |
+
$set: {
|
109 |
+
text: WorldString,
|
110 |
+
updatedAt: new Date(),
|
111 |
+
owner: existingUserKey.owner,
|
112 |
+
is_broadcast: true
|
113 |
+
}
|
114 |
+
},
|
115 |
{ upsert: true }
|
116 |
);
|
117 |
+
|
118 |
res.json({ message: `User ${userIdNumber} successfully broadcast`, is_broadcast: true });
|
119 |
|
120 |
} catch (error) {
|