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