Spaces:
Paused
Paused
| document.addEventListener("DOMContentLoaded", function() { | |
| // Prompt for admin API key (used for all admin requests) | |
| const adminApiKey = prompt("Enter your admin API key:"); | |
| // Add Credit Form submission | |
| document.getElementById("addCreditForm").addEventListener("submit", async function(e) { | |
| e.preventDefault(); | |
| const username = document.getElementById("username").value; | |
| const credits = parseInt(document.getElementById("credits").value, 10); | |
| const response = await fetch("/admin/add_credit", { | |
| method: "POST", | |
| headers: { | |
| "Content-Type": "application/json", | |
| "X-API-Key": adminApiKey | |
| }, | |
| body: JSON.stringify({ username, credits }) | |
| }); | |
| const result = await response.json(); | |
| alert(JSON.stringify(result, null, 2)); | |
| }); | |
| // Deactivate API Key Form submission | |
| document.getElementById("deactivateKeyForm").addEventListener("submit", async function(e) { | |
| e.preventDefault(); | |
| const key = document.getElementById("apiKeyToDeactivate").value; | |
| const response = await fetch("/admin/deactivate_key", { | |
| method: "POST", | |
| headers: { | |
| "Content-Type": "application/json", | |
| "X-API-Key": adminApiKey | |
| }, | |
| body: JSON.stringify({ key }) | |
| }); | |
| const result = await response.json(); | |
| alert(JSON.stringify(result, null, 2)); | |
| }); | |
| // Load Users Button | |
| document.getElementById("loadUsers").addEventListener("click", async function() { | |
| const response = await fetch("/admin/users", { | |
| headers: { | |
| "X-API-Key": adminApiKey | |
| } | |
| }); | |
| const result = await response.json(); | |
| document.getElementById("usersList").innerText = JSON.stringify(result, null, 2); | |
| }); | |
| }); | |