Update index.js
Browse files
index.js
CHANGED
@@ -281,7 +281,7 @@ app.post("/api/v2/key/upgrade-key", authenticateApiKey, apiLimiter, async (req,
|
|
281 |
const bannedCollection = dbClient.collection("banned_users");
|
282 |
const userIdNumber = Number(req.query.user_id);
|
283 |
const expire_number = Number(req.query.expire) || 0;
|
284 |
-
|
285 |
if (isNaN(userIdNumber) || userIdNumber === 0) {
|
286 |
return res.status(400).json({ error: "Invalid or missing user_id" });
|
287 |
}
|
@@ -300,9 +300,10 @@ app.post("/api/v2/key/upgrade-key", authenticateApiKey, apiLimiter, async (req,
|
|
300 |
const expirationDate = new Date();
|
301 |
expirationDate.setDate(expirationDate.getDate() + expire_number);
|
302 |
|
303 |
-
|
304 |
-
|
305 |
-
|
|
|
306 |
|
307 |
res.json({
|
308 |
apiKey: existingUser.key,
|
@@ -339,7 +340,7 @@ app.post('/api/v2/key/generate-key', authenticateApiKey, apiLimiter, async (req,
|
|
339 |
}
|
340 |
|
341 |
const expirationDate = new Date();
|
342 |
-
expirationDate.setDate(expirationDate.getDate() +
|
343 |
|
344 |
const userDocument = new ApiKey({
|
345 |
key: newKey,
|
|
|
281 |
const bannedCollection = dbClient.collection("banned_users");
|
282 |
const userIdNumber = Number(req.query.user_id);
|
283 |
const expire_number = Number(req.query.expire) || 0;
|
284 |
+
|
285 |
if (isNaN(userIdNumber) || userIdNumber === 0) {
|
286 |
return res.status(400).json({ error: "Invalid or missing user_id" });
|
287 |
}
|
|
|
300 |
const expirationDate = new Date();
|
301 |
expirationDate.setDate(expirationDate.getDate() + expire_number);
|
302 |
|
303 |
+
await ApiKey.updateOne(
|
304 |
+
{ owner: userIdNumber },
|
305 |
+
{ $set: { expiresAt: expirationDate, type: "premium" } }
|
306 |
+
);
|
307 |
|
308 |
res.json({
|
309 |
apiKey: existingUser.key,
|
|
|
340 |
}
|
341 |
|
342 |
const expirationDate = new Date();
|
343 |
+
expirationDate.setDate(expirationDate.getDate() + 30);
|
344 |
|
345 |
const userDocument = new ApiKey({
|
346 |
key: newKey,
|