Spaces:
Running
Running
Update static/admin.js
Browse files- static/admin.js +41 -14
static/admin.js
CHANGED
@@ -1,21 +1,48 @@
|
|
1 |
-
document.
|
|
|
|
|
|
|
|
|
|
|
2 |
e.preventDefault();
|
3 |
-
|
4 |
const username = document.getElementById("username").value;
|
5 |
const credits = parseInt(document.getElementById("credits").value, 10);
|
6 |
-
|
7 |
-
// Prompt for the admin API key
|
8 |
-
const apiKey = prompt("Enter your admin API key:");
|
9 |
-
|
10 |
const response = await fetch("/admin/add_credit", {
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
});
|
18 |
-
|
19 |
const result = await response.json();
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
});
|
|
|
1 |
+
document.addEventListener("DOMContentLoaded", function() {
|
2 |
+
// Prompt for admin API key (used for all admin requests)
|
3 |
+
const adminApiKey = prompt("Enter your admin API key:");
|
4 |
+
|
5 |
+
// Add Credit Form submission
|
6 |
+
document.getElementById("addCreditForm").addEventListener("submit", async function(e) {
|
7 |
e.preventDefault();
|
|
|
8 |
const username = document.getElementById("username").value;
|
9 |
const credits = parseInt(document.getElementById("credits").value, 10);
|
|
|
|
|
|
|
|
|
10 |
const response = await fetch("/admin/add_credit", {
|
11 |
+
method: "POST",
|
12 |
+
headers: {
|
13 |
+
"Content-Type": "application/json",
|
14 |
+
"X-API-Key": adminApiKey
|
15 |
+
},
|
16 |
+
body: JSON.stringify({ username, credits })
|
17 |
});
|
|
|
18 |
const result = await response.json();
|
19 |
+
alert(JSON.stringify(result, null, 2));
|
20 |
+
});
|
21 |
+
|
22 |
+
// Deactivate API Key Form submission
|
23 |
+
document.getElementById("deactivateKeyForm").addEventListener("submit", async function(e) {
|
24 |
+
e.preventDefault();
|
25 |
+
const key = document.getElementById("apiKeyToDeactivate").value;
|
26 |
+
const response = await fetch("/admin/deactivate_key", {
|
27 |
+
method: "POST",
|
28 |
+
headers: {
|
29 |
+
"Content-Type": "application/json",
|
30 |
+
"X-API-Key": adminApiKey
|
31 |
+
},
|
32 |
+
body: JSON.stringify({ key })
|
33 |
+
});
|
34 |
+
const result = await response.json();
|
35 |
+
alert(JSON.stringify(result, null, 2));
|
36 |
+
});
|
37 |
+
|
38 |
+
// Load Users Button
|
39 |
+
document.getElementById("loadUsers").addEventListener("click", async function() {
|
40 |
+
const response = await fetch("/admin/users", {
|
41 |
+
headers: {
|
42 |
+
"X-API-Key": adminApiKey
|
43 |
+
}
|
44 |
+
});
|
45 |
+
const result = await response.json();
|
46 |
+
document.getElementById("usersList").innerText = JSON.stringify(result, null, 2);
|
47 |
+
});
|
48 |
});
|