update
Browse files
index.js
CHANGED
@@ -275,6 +275,38 @@ app.get("/runtime", async (req, res) => {
|
|
275 |
res.send("Running lifetime");
|
276 |
})
|
277 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
278 |
|
279 |
app.post('/api/v2/key/generate-key', authenticateApiKey, apiLimiter, async (req, res) => {
|
280 |
try {
|
@@ -341,7 +373,7 @@ app.post("/api/v1/key/revoked-key", authenticateApiKey, apiLimiter, async (req,
|
|
341 |
|
342 |
if (!existingUser) {
|
343 |
return res.status(404).json({ error: "API key not found" });
|
344 |
-
|
345 |
|
346 |
if (existingUser) {
|
347 |
return res.status(200).json({
|
|
|
275 |
res.send("Running lifetime");
|
276 |
})
|
277 |
|
278 |
+
app.post("/api/v2/key/upgrade-key", authenticateApiKey, apiLimiter, async (req, res) => {
|
279 |
+
try {
|
280 |
+
const userIdNumber = Number(req.query.user_id);
|
281 |
+
|
282 |
+
if (isNaN(userIdNumber)) {
|
283 |
+
return res.status(400).json({ error: "Invalid or missing user_id" });
|
284 |
+
}
|
285 |
+
|
286 |
+
const existingUser = await ApiKey.findOne({ owner: userIdNumber });
|
287 |
+
|
288 |
+
if (!existingUser) {
|
289 |
+
return res.status(404).json({ error: "API key not found" });
|
290 |
+
}
|
291 |
+
|
292 |
+
const expirationDate = new Date();
|
293 |
+
expirationDate.setDate(expirationDate.getDate() + 5000);
|
294 |
+
|
295 |
+
existingUser.expiresAt = expirationDate;
|
296 |
+
existingUser.type = "premium";
|
297 |
+
await existingUser.save();
|
298 |
+
|
299 |
+
res.json({
|
300 |
+
apiKey: existingUser.key,
|
301 |
+
createdAt: existingUser.createdAt,
|
302 |
+
expiresAt: expirationDate,
|
303 |
+
owner: userIdNumber,
|
304 |
+
type: "premium"
|
305 |
+
});
|
306 |
+
} catch (error) {
|
307 |
+
res.status(500).json({ error: `Key upgrade failed: ${error.message}` });
|
308 |
+
}
|
309 |
+
});
|
310 |
|
311 |
app.post('/api/v2/key/generate-key', authenticateApiKey, apiLimiter, async (req, res) => {
|
312 |
try {
|
|
|
373 |
|
374 |
if (!existingUser) {
|
375 |
return res.status(404).json({ error: "API key not found" });
|
376 |
+
}
|
377 |
|
378 |
if (existingUser) {
|
379 |
return res.status(200).json({
|