Spaces:
Running
Running
Create static/admin.js
Browse files- static/admin.js +21 -0
static/admin.js
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
document.getElementById("addCreditForm").addEventListener("submit", async function(e) {
|
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 |
+
method: "POST",
|
12 |
+
headers: {
|
13 |
+
"Content-Type": "application/json",
|
14 |
+
"X-API-Key": apiKey
|
15 |
+
},
|
16 |
+
body: JSON.stringify({ username, credits })
|
17 |
+
});
|
18 |
+
|
19 |
+
const result = await response.json();
|
20 |
+
document.getElementById("result").innerText = JSON.stringify(result, null, 2);
|
21 |
+
});
|