Spaces:
Sleeping
Sleeping
| <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> |