Spaces:
Runtime error
Runtime error
document.addEventListener("DOMContentLoaded", function() { | |
// Prompt for user API key (used for all user requests) | |
const userApiKey = prompt("Enter your API key:"); | |
// Generate API Key Form submission | |
document.getElementById("generateKeyForm").addEventListener("submit", async function(e) { | |
e.preventDefault(); | |
let expiry_date = document.getElementById("expiry_date").value; | |
expiry_date = expiry_date ? expiry_date : null; | |
const response = await fetch("/user/generate_key", { | |
method: "POST", | |
headers: { | |
"Content-Type": "application/json", | |
"X-API-Key": userApiKey | |
}, | |
body: JSON.stringify({ expiry_date }) | |
}); | |
const result = await response.json(); | |
alert("New API Key: " + result.key); | |
}); | |
// Load API Keys Button | |
document.getElementById("loadApiKeys").addEventListener("click", async function() { | |
const response = await fetch("/user/api_keys", { | |
headers: { | |
"X-API-Key": userApiKey | |
} | |
}); | |
const result = await response.json(); | |
document.getElementById("apiKeysList").innerText = JSON.stringify(result, null, 2); | |
}); | |
// Test API Button | |
document.getElementById("testApiButton").addEventListener("click", async function() { | |
const response = await fetch("/user/test_api", { | |
headers: { | |
"X-API-Key": userApiKey | |
} | |
}); | |
const result = await response.json(); | |
document.getElementById("apiTestResult").innerText = JSON.stringify(result, null, 2); | |
}); | |
}); | |