Spaces:
Sleeping
Sleeping
File size: 2,883 Bytes
7998d46 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | <!DOCTYPE html>
<html>
<head>
<title>Admin - Add Command</title>
<style>
body { font-family: Arial, sans-serif; margin: 20px; }
input, textarea { display: block; margin: 10px 0; padding: 8px; width: 300px; }
button { padding: 10px 15px; background: green; color: white; border: none; cursor: pointer; }
button:hover { background: darkgreen; }
.message { margin-top: 15px; }
</style>
</head>
<body>
<h1>Admin Panel - Add Command</h1>
<form id="commandForm">
<label>API Key:</label>
<input type="text" id="apiKey" placeholder="Enter API Key" required>
<label>Command Name:</label>
<input type="text" id="name" placeholder="Enter command name" required>
<label>Category:</label>
<input type="text" id="category" placeholder="Enter category" required>
<label>Info:</label>
<textarea id="info" placeholder="Enter command info" required></textarea>
<button type="submit">Add Command</button>
</form>
<div class="message" id="message"></div>
<script>
// Load API key from localStorage if available
const savedKey = localStorage.getItem('adminApiKey');
if (savedKey) {
document.getElementById('apiKey').value = savedKey;
}
document.getElementById('commandForm').addEventListener('submit', async (e) => {
e.preventDefault();
const apiKey = document.getElementById('apiKey').value;
const name = document.getElementById('name').value;
const category = document.getElementById('category').value;
const info = document.getElementById('info').value;
// Save API key in localStorage for next time
localStorage.setItem('adminApiKey', apiKey);
try {
const res = await fetch('/api/commands', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': apiKey
},
body: JSON.stringify({ name, category, info })
});
const data = await res.json();
if (res.ok) {
document.getElementById('message').innerHTML = `<p style="color:green">${data.message}</p>`;
document.getElementById('commandForm').reset();
document.getElementById('apiKey').value = apiKey; // Keep the API key after reset
} else {
document.getElementById('message').innerHTML = `<p style="color:red">${data.error}</p>`;
}
} catch (err) {
document.getElementById('message').innerHTML = `<p style="color:red">Error: ${err.message}</p>`;
}
});
</script>
</body>
</html> |