Update index.js
Browse files
index.js
CHANGED
@@ -120,30 +120,6 @@ app.delete("/v1/delete-key", async (req, res) => {
|
|
120 |
}
|
121 |
});
|
122 |
|
123 |
-
app.get("/v1/show-key", async (req, res) => {
|
124 |
-
const dbClient = new Database("AkenoXJs");
|
125 |
-
const collection = dbClient.collection("api_keys");
|
126 |
-
const apiKey = req.query.api_key;
|
127 |
-
|
128 |
-
if (!apiKey) {
|
129 |
-
return res.status(400).json({ error: "Missing 'api_key' parameter" });
|
130 |
-
}
|
131 |
-
|
132 |
-
try {
|
133 |
-
const DocsKey = await collection.findOne({ key: apiKey });
|
134 |
-
|
135 |
-
if (DocsKey) {
|
136 |
-
res.json({
|
137 |
-
owner: DocsKey.owner,
|
138 |
-
createdAt: DocsKey.createdAt
|
139 |
-
});
|
140 |
-
} else {
|
141 |
-
res.status(404).json({ message: "API key not found" });
|
142 |
-
}
|
143 |
-
} catch (err) {
|
144 |
-
res.status(500).json({ error: `Key retrieval failed: ${err.message}` });
|
145 |
-
}
|
146 |
-
});
|
147 |
|
148 |
app.get("/v1/test", authenticateApiKey, apiLimiter, async (req, res) => {
|
149 |
res.json({ message: "access key" });
|
@@ -176,7 +152,12 @@ app.post("/v1/revoked-key", async (req, res) => {
|
|
176 |
);
|
177 |
|
178 |
if (result.modifiedCount > 0) {
|
179 |
-
res.json({
|
|
|
|
|
|
|
|
|
|
|
180 |
} else {
|
181 |
res.status(500).json({ error: "Failed to update API key" });
|
182 |
}
|
@@ -201,7 +182,11 @@ app.post('/v1/generate-key', async (req, res) => {
|
|
201 |
const existingUser = await collection.findOne({ owner: userIdNumber });
|
202 |
|
203 |
if (existingUser) {
|
204 |
-
return res.status(200).json({
|
|
|
|
|
|
|
|
|
205 |
}
|
206 |
const userDocument = {
|
207 |
key: newKey,
|
|
|
120 |
}
|
121 |
});
|
122 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
|
124 |
app.get("/v1/test", authenticateApiKey, apiLimiter, async (req, res) => {
|
125 |
res.json({ message: "access key" });
|
|
|
152 |
);
|
153 |
|
154 |
if (result.modifiedCount > 0) {
|
155 |
+
res.json({
|
156 |
+
message: "API key successfully revoked and regenerated",
|
157 |
+
apiKey: newKey,
|
158 |
+
createdAt: new Date(),
|
159 |
+
owner: userIdNumber
|
160 |
+
});
|
161 |
} else {
|
162 |
res.status(500).json({ error: "Failed to update API key" });
|
163 |
}
|
|
|
182 |
const existingUser = await collection.findOne({ owner: userIdNumber });
|
183 |
|
184 |
if (existingUser) {
|
185 |
+
return res.status(200).json({
|
186 |
+
apiKey: existingUser.key,
|
187 |
+
createdAt: existingUser.createdAt,
|
188 |
+
owner: existingUser.owner
|
189 |
+
});
|
190 |
}
|
191 |
const userDocument = {
|
192 |
key: newKey,
|