Update index.js
Browse files
index.js
CHANGED
@@ -82,41 +82,54 @@ app.use(
|
|
82 |
app.use(express.static('public'));
|
83 |
|
84 |
app.delete("/v1/delete-key", async (req, res) => {
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
}
|
95 |
-
} catch (err) {
|
96 |
-
res.status(500).json({ error: `Key failed: ${err.message}` });
|
97 |
-
}
|
98 |
});
|
99 |
|
100 |
app.get("/v1/show-key", async (req, res) => {
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
}
|
113 |
-
} catch (err) {
|
114 |
-
res.status(500).json({ error: `Key failed: ${err.message}` });
|
115 |
-
}
|
116 |
});
|
117 |
|
118 |
app.post('/v1/generate-key', async (req, res) => {
|
119 |
-
const dbClient = new Database("AkenoXJs"
|
120 |
const collection = dbClient.collection('api_keys');
|
121 |
try {
|
122 |
const newKey = generateAkenoKey();
|
|
|
82 |
app.use(express.static('public'));
|
83 |
|
84 |
app.delete("/v1/delete-key", async (req, res) => {
|
85 |
+
const dbClient = new Database("AkenoXJs");
|
86 |
+
const collection = dbClient.collection("api_keys");
|
87 |
+
const apiKey = req.query.api_key;
|
88 |
+
|
89 |
+
if (!apiKey) {
|
90 |
+
return res.status(400).json({ error: "Missing 'api_key' parameter" });
|
91 |
+
}
|
92 |
+
|
93 |
+
try {
|
94 |
+
const DocsKey = await collection.deleteOne({ key: apiKey });
|
95 |
+
|
96 |
+
if (DocsKey.deletedCount > 0) {
|
97 |
+
res.json({ message: "API key has been successfully deleted" });
|
98 |
+
} else {
|
99 |
+
res.status(404).json({ message: "API key not found" });
|
100 |
+
}
|
101 |
+
} catch (err) {
|
102 |
+
res.status(500).json({ error: `Key deletion failed: ${err.message}` });
|
103 |
}
|
|
|
|
|
|
|
104 |
});
|
105 |
|
106 |
app.get("/v1/show-key", async (req, res) => {
|
107 |
+
const dbClient = new Database("AkenoXJs");
|
108 |
+
const collection = dbClient.collection("api_keys");
|
109 |
+
const apiKey = req.query.api_key;
|
110 |
+
|
111 |
+
if (!apiKey) {
|
112 |
+
return res.status(400).json({ error: "Missing 'api_key' parameter" });
|
113 |
+
}
|
114 |
+
|
115 |
+
try {
|
116 |
+
const DocsKey = await collection.findOne({ key: apiKey });
|
117 |
+
|
118 |
+
if (DocsKey) {
|
119 |
+
res.json({
|
120 |
+
owner: DocsKey.owner,
|
121 |
+
createdAt: DocsKey.createdAt
|
122 |
+
});
|
123 |
+
} else {
|
124 |
+
res.status(404).json({ message: "API key not found" });
|
125 |
+
}
|
126 |
+
} catch (err) {
|
127 |
+
res.status(500).json({ error: `Key retrieval failed: ${err.message}` });
|
128 |
}
|
|
|
|
|
|
|
129 |
});
|
130 |
|
131 |
app.post('/v1/generate-key', async (req, res) => {
|
132 |
+
const dbClient = new Database("AkenoXJs");
|
133 |
const collection = dbClient.collection('api_keys');
|
134 |
try {
|
135 |
const newKey = generateAkenoKey();
|