Spaces:
Runtime error
Runtime error
Update static/user.js
Browse files- static/user.js +39 -10
static/user.js
CHANGED
@@ -1,14 +1,43 @@
|
|
1 |
-
document.
|
2 |
-
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
const response = await fetch("/user/test_api", {
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
}
|
10 |
});
|
11 |
-
|
12 |
const result = await response.json();
|
13 |
-
document.getElementById("
|
|
|
14 |
});
|
|
|
1 |
+
document.addEventListener("DOMContentLoaded", function() {
|
2 |
+
// Prompt for user API key (used for all user requests)
|
3 |
+
const userApiKey = prompt("Enter your API key:");
|
4 |
+
|
5 |
+
// Generate API Key Form submission
|
6 |
+
document.getElementById("generateKeyForm").addEventListener("submit", async function(e) {
|
7 |
+
e.preventDefault();
|
8 |
+
let expiry_date = document.getElementById("expiry_date").value;
|
9 |
+
expiry_date = expiry_date ? expiry_date : null;
|
10 |
+
const response = await fetch("/user/generate_key", {
|
11 |
+
method: "POST",
|
12 |
+
headers: {
|
13 |
+
"Content-Type": "application/json",
|
14 |
+
"X-API-Key": userApiKey
|
15 |
+
},
|
16 |
+
body: JSON.stringify({ expiry_date })
|
17 |
+
});
|
18 |
+
const result = await response.json();
|
19 |
+
alert("New API Key: " + result.key);
|
20 |
+
});
|
21 |
+
|
22 |
+
// Load API Keys Button
|
23 |
+
document.getElementById("loadApiKeys").addEventListener("click", async function() {
|
24 |
+
const response = await fetch("/user/api_keys", {
|
25 |
+
headers: {
|
26 |
+
"X-API-Key": userApiKey
|
27 |
+
}
|
28 |
+
});
|
29 |
+
const result = await response.json();
|
30 |
+
document.getElementById("apiKeysList").innerText = JSON.stringify(result, null, 2);
|
31 |
+
});
|
32 |
+
|
33 |
+
// Test API Button
|
34 |
+
document.getElementById("testApiButton").addEventListener("click", async function() {
|
35 |
const response = await fetch("/user/test_api", {
|
36 |
+
headers: {
|
37 |
+
"X-API-Key": userApiKey
|
38 |
+
}
|
|
|
39 |
});
|
|
|
40 |
const result = await response.json();
|
41 |
+
document.getElementById("apiTestResult").innerText = JSON.stringify(result, null, 2);
|
42 |
+
});
|
43 |
});
|