Spaces:
XCAPI
/
Sleeping

XCAPI commited on
Commit
e09a4d1
·
verified ·
1 Parent(s): aa48e9e

Upload admin.html

Browse files
Files changed (1) hide show
  1. templates/admin.html +198 -0
templates/admin.html ADDED
@@ -0,0 +1,198 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>代理管理界面</title>
5
+ <style>
6
+ body {
7
+ font-family: Arial, sans-serif;
8
+ max-width: 1200px;
9
+ margin: 0 auto;
10
+ padding: 20px;
11
+ }
12
+ .container {
13
+ display: flex;
14
+ gap: 20px;
15
+ }
16
+ .section {
17
+ flex: 1;
18
+ background: #f5f5f5;
19
+ padding: 20px;
20
+ border-radius: 8px;
21
+ }
22
+ table {
23
+ width: 100%;
24
+ border-collapse: collapse;
25
+ margin: 10px 0;
26
+ }
27
+ th, td {
28
+ padding: 8px;
29
+ border: 1px solid #ddd;
30
+ text-align: left;
31
+ }
32
+ th { background: #eee; }
33
+ .enabled { color: green; }
34
+ .disabled { color: red; }
35
+ .form-group {
36
+ margin: 10px 0;
37
+ }
38
+ button {
39
+ padding: 5px 10px;
40
+ margin: 2px;
41
+ cursor: pointer;
42
+ }
43
+ .status-bar {
44
+ background: #e0e0e0;
45
+ padding: 10px;
46
+ margin: 10px 0;
47
+ border-radius: 4px;
48
+ }
49
+ </style>
50
+ </head>
51
+ <body>
52
+ <h1>代理管理界面</h1>
53
+
54
+ <div class="status-bar">
55
+ <strong>系统状态:</strong>
56
+ Models代理数: <span id="modelsCount">0</span> |
57
+ Chat代理数: <span id="chatCount">0</span>
58
+ </div>
59
+
60
+ <div class="container">
61
+ <div class="section">
62
+ <h2>Models代理列表</h2>
63
+ <table id="modelsTable">
64
+ <tr>
65
+ <th>URL</th>
66
+ <th>权重</th>
67
+ <th>状态</th>
68
+ <th>操作</th>
69
+ </tr>
70
+ </table>
71
+
72
+ <h3>添加Models代理</h3>
73
+ <div class="form-group">
74
+ <input type="text" id="modelsUrl" placeholder="URL">
75
+ <input type="number" id="modelsWeight" placeholder="权重" value="1">
76
+ <button onclick="addTarget('models')">添加</button>
77
+ </div>
78
+ </div>
79
+
80
+ <div class="section">
81
+ <h2>Chat代理列表</h2>
82
+ <table id="chatTable">
83
+ <tr>
84
+ <th>URL</th>
85
+ <th>权重</th>
86
+ <th>状态</th>
87
+ <th>操作</th>
88
+ </tr>
89
+ </table>
90
+
91
+ <h3>添加Chat代理</h3>
92
+ <div class="form-group">
93
+ <input type="text" id="chatUrl" placeholder="URL">
94
+ <input type="number" id="chatWeight" placeholder="权重" value="1">
95
+ <button onclick="addTarget('chat')">添加</button>
96
+ </div>
97
+ </div>
98
+ </div>
99
+
100
+ <script>
101
+ const password = new URLSearchParams(window.location.search).get('password');
102
+
103
+ function updateTables() {
104
+ fetch('/admin/api/targets?password=' + password)
105
+ .then(response => response.json())
106
+ .then(data => {
107
+ document.getElementById('modelsCount').textContent = data.models.length;
108
+ document.getElementById('chatCount').textContent = data.chat.length;
109
+
110
+ updateTable('models', data.models);
111
+ updateTable('chat', data.chat);
112
+ });
113
+ }
114
+
115
+ function updateTable(type, targets) {
116
+ const table = document.getElementById(type + 'Table');
117
+ // 保留表头
118
+ while (table.rows.length > 1) {
119
+ table.deleteRow(1);
120
+ }
121
+
122
+ targets.forEach((target, index) => {
123
+ const row = table.insertRow();
124
+ row.innerHTML = `
125
+ <td>${target.url}</td>
126
+ <td>${target.weight}</td>
127
+ <td class="${target.enabled ? 'enabled' : 'disabled'}">
128
+ ${target.enabled ? '启用' : '禁用'}
129
+ </td>
130
+ <td>
131
+ <button onclick="toggleTarget('${type}', '${target.url}')">
132
+ ${target.enabled ? '禁用' : '启用'}
133
+ </button>
134
+ <button onclick="deleteTarget('${type}', '${target.url}')">删除</button>
135
+ </td>
136
+ `;
137
+ });
138
+ }
139
+
140
+ function addTarget(type) {
141
+ const url = document.getElementById(type + 'Url').value;
142
+ const weight = document.getElementById(type + 'Weight').value;
143
+
144
+ fetch('/admin/api/target', {
145
+ method: 'POST',
146
+ headers: {
147
+ 'Content-Type': 'application/json',
148
+ },
149
+ body: JSON.stringify({
150
+ type: type,
151
+ url: url,
152
+ weight: parseInt(weight),
153
+ password: password
154
+ })
155
+ }).then(() => {
156
+ document.getElementById(type + 'Url').value = '';
157
+ document.getElementById(type + 'Weight').value = '1';
158
+ updateTables();
159
+ });
160
+ }
161
+
162
+ function toggleTarget(type, url) {
163
+ fetch('/admin/api/target/toggle', {
164
+ method: 'POST',
165
+ headers: {
166
+ 'Content-Type': 'application/json',
167
+ },
168
+ body: JSON.stringify({
169
+ type: type,
170
+ url: url,
171
+ password: password
172
+ })
173
+ }).then(() => updateTables());
174
+ }
175
+
176
+ function deleteTarget(type, url) {
177
+ if (!confirm('确定要删除这个代理地址吗?')) return;
178
+
179
+ fetch('/admin/api/target', {
180
+ method: 'DELETE',
181
+ headers: {
182
+ 'Content-Type': 'application/json',
183
+ },
184
+ body: JSON.stringify({
185
+ type: type,
186
+ url: url,
187
+ password: password
188
+ })
189
+ }).then(() => updateTables());
190
+ }
191
+
192
+ // 初始加载
193
+ updateTables();
194
+ // 定时刷新
195
+ setInterval(updateTables, 5000);
196
+ </script>
197
+ </body>
198
+ </html>