Update index.js
Browse files
index.js
CHANGED
@@ -183,7 +183,6 @@ app.delete("/api/v1/delete-key", async (req, res) => {
|
|
183 |
}
|
184 |
});
|
185 |
|
186 |
-
|
187 |
app.get("/api/v1/test", authenticateApiKey, apiLimiter, async (req, res) => {
|
188 |
res.json({ message: "access key" });
|
189 |
})
|
@@ -213,18 +212,19 @@ app.post('/api/v2/generate-key', async (req, res) => {
|
|
213 |
});
|
214 |
}
|
215 |
|
216 |
-
const
|
217 |
-
|
218 |
|
219 |
const userDocument = new ApiKey({
|
220 |
key: newKey,
|
221 |
createdAt: new Date(),
|
222 |
-
expiresAt,
|
223 |
owner: userIdNumber,
|
224 |
-
email: email || null
|
|
|
225 |
});
|
226 |
await userDocument.save();
|
227 |
-
res.json({ apiKey: newKey, createdAt: new Date(), expiresAt:
|
228 |
} catch (err) {
|
229 |
res.status(500).json({ error: `Key generation failed: ${err.message}` });
|
230 |
}
|
@@ -296,7 +296,8 @@ app.post('/api/v1/generate-key', async (req, res) => {
|
|
296 |
const userDocument = {
|
297 |
key: newKey,
|
298 |
createdAt: new Date(),
|
299 |
-
owner: userIdNumber
|
|
|
300 |
};
|
301 |
if (email) {
|
302 |
userDocument.email = email;
|
|
|
183 |
}
|
184 |
});
|
185 |
|
|
|
186 |
app.get("/api/v1/test", authenticateApiKey, apiLimiter, async (req, res) => {
|
187 |
res.json({ message: "access key" });
|
188 |
})
|
|
|
212 |
});
|
213 |
}
|
214 |
|
215 |
+
const expirationDate = new Date();
|
216 |
+
expirationDate.setDate(expirationDate.getDate() + 30);
|
217 |
|
218 |
const userDocument = new ApiKey({
|
219 |
key: newKey,
|
220 |
createdAt: new Date(),
|
221 |
+
expiresAt: expirationDate,
|
222 |
owner: userIdNumber,
|
223 |
+
email: email || null,
|
224 |
+
type: "premium"
|
225 |
});
|
226 |
await userDocument.save();
|
227 |
+
res.json({ apiKey: newKey, createdAt: new Date(), expiresAt: expirationDate, owner: userIdNumber });
|
228 |
} catch (err) {
|
229 |
res.status(500).json({ error: `Key generation failed: ${err.message}` });
|
230 |
}
|
|
|
296 |
const userDocument = {
|
297 |
key: newKey,
|
298 |
createdAt: new Date(),
|
299 |
+
owner: userIdNumber,
|
300 |
+
type: "free"
|
301 |
};
|
302 |
if (email) {
|
303 |
userDocument.email = email;
|