bobocup commited on
Commit
c298b8e
·
verified ·
1 Parent(s): 9c30f7b

Create static/admin.html

Browse files
Files changed (1) hide show
  1. static/admin.html +167 -0
static/admin.html ADDED
@@ -0,0 +1,167 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>API Keys Management</title>
5
+ <style>
6
+ body {
7
+ font-family: Arial, sans-serif;
8
+ max-width: 800px;
9
+ margin: 0 auto;
10
+ padding: 20px;
11
+ }
12
+ #loginForm, #mainContent {
13
+ margin: 20px 0;
14
+ }
15
+ .key-item {
16
+ display: flex;
17
+ align-items: center;
18
+ padding: 10px;
19
+ border: 1px solid #ddd;
20
+ margin: 5px 0;
21
+ }
22
+ .key-text {
23
+ flex-grow: 1;
24
+ }
25
+ button {
26
+ padding: 5px 10px;
27
+ margin: 0 5px;
28
+ }
29
+ .status {
30
+ margin-left: 10px;
31
+ }
32
+ .valid { color: green; }
33
+ .invalid { color: red; }
34
+ </style>
35
+ </head>
36
+ <body>
37
+ <h1>API Keys Management</h1>
38
+
39
+ <!-- 登录表单 -->
40
+ <div id="loginForm">
41
+ <input type="password" id="password" placeholder="Enter admin password">
42
+ <button onclick="login()">Login</button>
43
+ </div>
44
+
45
+ <!-- 主要内容(默认隐藏) -->
46
+ <div id="mainContent" style="display: none;">
47
+ <div>
48
+ <input type="text" id="newKey" placeholder="Enter new API key" style="width: 300px;">
49
+ <button onclick="addKey()">Add Key</button>
50
+ </div>
51
+
52
+ <div id="keyList">
53
+ <!-- Keys will be listed here -->
54
+ </div>
55
+ </div>
56
+
57
+ <script>
58
+ let adminPassword = '';
59
+
60
+ // 登录
61
+ async function login() {
62
+ const password = document.getElementById('password').value;
63
+ try {
64
+ const response = await fetch('/api/admin/login', {
65
+ method: 'POST',
66
+ headers: {'Content-Type': 'application/json'},
67
+ body: JSON.stringify({password: password})
68
+ });
69
+
70
+ if (response.ok) {
71
+ adminPassword = password;
72
+ document.getElementById('loginForm').style.display = 'none';
73
+ document.getElementById('mainContent').style.display = 'block';
74
+ loadKeys();
75
+ } else {
76
+ alert('Invalid password');
77
+ }
78
+ } catch (error) {
79
+ alert('Login failed');
80
+ }
81
+ }
82
+
83
+ // 加载keys
84
+ async function loadKeys() {
85
+ try {
86
+ const response = await fetch(`/api/keys?password=${encodeURIComponent(adminPassword)}`);
87
+ const data = await response.json();
88
+ const keyList = document.getElementById('keyList');
89
+ keyList.innerHTML = '';
90
+
91
+ for (const key of data.keys) {
92
+ const keyItem = document.createElement('div');
93
+ keyItem.className = 'key-item';
94
+ keyItem.innerHTML = `
95
+ <div class="key-text">${key}</div>
96
+ <button onclick="checkKey('${key}')">Check</button>
97
+ <button onclick="deleteKey('${key}')">Delete</button>
98
+ <span class="status" id="status-${key}"></span>
99
+ `;
100
+ keyList.appendChild(keyItem);
101
+ }
102
+ } catch (error) {
103
+ alert('Error loading keys');
104
+ }
105
+ }
106
+
107
+ // 添加key
108
+ async function addKey() {
109
+ const key = document.getElementById('newKey').value.trim();
110
+ if (!key) return;
111
+
112
+ try {
113
+ const response = await fetch(`/api/keys?key=${encodeURIComponent(key)}&password=${encodeURIComponent(adminPassword)}`, {
114
+ method: 'POST'
115
+ });
116
+
117
+ if (response.ok) {
118
+ document.getElementById('newKey').value = '';
119
+ loadKeys();
120
+ alert('Key added successfully');
121
+ } else {
122
+ alert('Error adding key');
123
+ }
124
+ } catch (error) {
125
+ alert('Error adding key');
126
+ }
127
+ }
128
+
129
+ // 删除key
130
+ async function deleteKey(key) {
131
+ if (!confirm('Are you sure you want to delete this key?')) return;
132
+
133
+ try {
134
+ const response = await fetch(`/api/keys/${encodeURIComponent(key)}?password=${encodeURIComponent(adminPassword)}`, {
135
+ method: 'DELETE'
136
+ });
137
+
138
+ if (response.ok) {
139
+ loadKeys();
140
+ alert('Key deleted successfully');
141
+ } else {
142
+ alert('Error deleting key');
143
+ }
144
+ } catch (error) {
145
+ alert('Error deleting key');
146
+ }
147
+ }
148
+
149
+ // 检查key
150
+ async function checkKey(key) {
151
+ const statusSpan = document.getElementById(`status-${key}`);
152
+ statusSpan.textContent = 'Checking...';
153
+
154
+ try {
155
+ const response = await fetch(`/api/keys/check/${encodeURIComponent(key)}?password=${encodeURIComponent(adminPassword)}`);
156
+ const data = await response.json();
157
+
158
+ statusSpan.textContent = data.valid ? '✓ Valid' : '✗ Invalid';
159
+ statusSpan.className = `status ${data.valid ? 'valid' : 'invalid'}`;
160
+ } catch (error) {
161
+ statusSpan.textContent = '✗ Error';
162
+ statusSpan.className = 'status invalid';
163
+ }
164
+ }
165
+ </script>
166
+ </body>
167
+ </html>