Spaces:
Paused
Paused
Redesign admin panel: dark Claude Code UI + root redirect to /admin/
Browse files- emergent2api/app.py +2 -17
- emergent2api/static/admin/index.html +284 -294
emergent2api/app.py
CHANGED
|
@@ -8,7 +8,7 @@ import pathlib
|
|
| 8 |
|
| 9 |
from fastapi import FastAPI, Request
|
| 10 |
from fastapi.middleware.cors import CORSMiddleware
|
| 11 |
-
from fastapi.responses import FileResponse, JSONResponse
|
| 12 |
|
| 13 |
from .config import settings
|
| 14 |
from . import database as db
|
|
@@ -108,22 +108,7 @@ _STATIC_DIR = pathlib.Path(__file__).parent / "static" / "admin"
|
|
| 108 |
|
| 109 |
@app.get("/")
|
| 110 |
async def root():
|
| 111 |
-
|
| 112 |
-
return {
|
| 113 |
-
"service": "Emergent2API",
|
| 114 |
-
"version": "0.3.0",
|
| 115 |
-
"backend": settings.backend,
|
| 116 |
-
"accounts": count,
|
| 117 |
-
"endpoints": {
|
| 118 |
-
"api": [
|
| 119 |
-
"POST /v1/chat/completions (OpenAI)",
|
| 120 |
-
"POST /v1/messages (Anthropic)",
|
| 121 |
-
"POST /v1/responses (OpenAI Response API)",
|
| 122 |
-
"GET /v1/models",
|
| 123 |
-
],
|
| 124 |
-
"admin": "/admin/",
|
| 125 |
-
},
|
| 126 |
-
}
|
| 127 |
|
| 128 |
|
| 129 |
@app.get("/admin")
|
|
|
|
| 8 |
|
| 9 |
from fastapi import FastAPI, Request
|
| 10 |
from fastapi.middleware.cors import CORSMiddleware
|
| 11 |
+
from fastapi.responses import FileResponse, JSONResponse, RedirectResponse
|
| 12 |
|
| 13 |
from .config import settings
|
| 14 |
from . import database as db
|
|
|
|
| 108 |
|
| 109 |
@app.get("/")
|
| 110 |
async def root():
|
| 111 |
+
return RedirectResponse(url="/admin/")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
|
| 113 |
|
| 114 |
@app.get("/admin")
|
emergent2api/static/admin/index.html
CHANGED
|
@@ -3,228 +3,254 @@
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
| 5 |
<title>Emergent2API</title>
|
|
|
|
|
|
|
| 6 |
<style>
|
| 7 |
-
:root{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
*{margin:0;padding:0;box-sizing:border-box}
|
| 9 |
-
body{font-family:-
|
| 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 |
tr:last-child td{border-bottom:none}
|
| 56 |
-
tr:hover td{background:
|
| 57 |
-
.
|
| 58 |
-
.badge{display:inline-
|
| 59 |
-
.badge
|
| 60 |
-
.
|
| 61 |
-
.
|
| 62 |
-
.
|
| 63 |
-
.
|
| 64 |
-
.
|
| 65 |
-
.
|
| 66 |
-
.
|
| 67 |
-
.
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
.
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
.
|
| 74 |
-
.
|
| 75 |
-
.
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
.
|
| 79 |
-
.
|
| 80 |
-
.
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
.
|
| 84 |
-
.
|
| 85 |
-
.
|
| 86 |
-
.
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
.
|
| 90 |
-
.
|
| 91 |
-
.
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
.doc
|
| 96 |
-
.doc
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
.
|
| 100 |
-
.
|
| 101 |
-
.
|
| 102 |
-
.
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
.
|
| 106 |
-
.login-card button:hover{opacity:.85}
|
| 107 |
-
.login-err{color:var(--red);font-size:12px;display:none;margin-top:8px}
|
| 108 |
-
|
| 109 |
-
/* TOAST */
|
| 110 |
-
.toast{position:fixed;bottom:20px;right:20px;background:var(--primary);color:#fff;padding:10px 18px;border-radius:8px;font-size:13px;z-index:300;opacity:0;transition:opacity .25s;pointer-events:none}
|
| 111 |
.toast.show{opacity:1}
|
| 112 |
|
| 113 |
-
@media(max-width:768px){
|
| 114 |
-
.stats{grid-template-columns:repeat(2,1fr)}
|
| 115 |
-
.nav-links{font-size:13px}
|
| 116 |
-
.page{padding:16px}
|
| 117 |
-
}
|
| 118 |
</style>
|
| 119 |
</head>
|
| 120 |
<body>
|
| 121 |
|
| 122 |
-
<
|
| 123 |
-
<div
|
| 124 |
-
<div class="login-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
<
|
|
|
|
|
|
|
|
|
|
| 131 |
</div>
|
| 132 |
|
| 133 |
-
<
|
| 134 |
-
<div
|
| 135 |
-
<
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
<span class="nav-link active" data-page="tokens" onclick="showPage('tokens')">Token管理</span>
|
| 139 |
-
<span class="nav-link" data-page="config" onclick="showPage('config')">配置管理</span>
|
| 140 |
-
<span class="nav-link" data-page="docs" onclick="showPage('docs')">使用文档</span>
|
| 141 |
</div>
|
| 142 |
-
<div class="
|
| 143 |
-
<
|
|
|
|
|
|
|
| 144 |
</div>
|
| 145 |
-
</
|
|
|
|
|
|
|
|
|
|
| 146 |
|
| 147 |
-
<!--
|
| 148 |
-
<div id="
|
| 149 |
-
<div class="
|
| 150 |
-
<div class="page-desc">管理 Emergent2API 的 Token 服务号池。</div>
|
| 151 |
<div class="stats">
|
| 152 |
-
<div class="
|
| 153 |
-
<div class="
|
| 154 |
-
<div class="
|
| 155 |
-
<div class="
|
| 156 |
</div>
|
| 157 |
-
<div class="
|
| 158 |
-
<
|
| 159 |
-
<
|
| 160 |
-
<
|
| 161 |
-
<span class="
|
| 162 |
-
<button class="
|
| 163 |
-
<button class="
|
| 164 |
-
<button class="
|
| 165 |
-
<button class="
|
| 166 |
</div>
|
| 167 |
-
<div class="
|
| 168 |
-
<table>
|
| 169 |
-
<
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
<tbody id="tbody"></tbody>
|
| 174 |
-
</table>
|
| 175 |
-
<div class="pagination" id="pager"></div>
|
| 176 |
</div>
|
| 177 |
</div>
|
| 178 |
|
| 179 |
-
<!-- CONFIG
|
| 180 |
-
<div id="
|
| 181 |
-
<div class="
|
| 182 |
-
<div class="
|
| 183 |
-
|
| 184 |
-
<
|
| 185 |
-
|
| 186 |
-
<div
|
| 187 |
-
<div style="padding-bottom:14px"><button class="action-btn btn-dark" onclick="genKey()">生成</button></div>
|
| 188 |
</div>
|
| 189 |
-
<div class="
|
| 190 |
-
<label>
|
| 191 |
-
<select id="cfg-backend"><option value="jobs">Jobs API(无 IP 限制)</option><option value="integrations">Integrations API(更快,需
|
| 192 |
</div>
|
| 193 |
-
<div class="
|
| 194 |
</div>
|
| 195 |
-
<div class="
|
| 196 |
-
<h3>
|
| 197 |
-
<div class="
|
| 198 |
</div>
|
| 199 |
<div style="display:flex;gap:8px;justify-content:flex-end">
|
| 200 |
-
<button class="
|
| 201 |
-
<button class="
|
| 202 |
</div>
|
| 203 |
</div>
|
| 204 |
|
| 205 |
-
<!-- DOCS
|
| 206 |
-
<div id="
|
| 207 |
-
<div class="
|
| 208 |
-
<div class="
|
| 209 |
-
<div class="doc-section">
|
| 210 |
<h3>可用模型</h3>
|
| 211 |
-
<table
|
| 212 |
-
<tr><td><code>claude-opus-4-6</code></td><td>Claude Opus 4.6
|
| 213 |
<tr><td><code>claude-sonnet-4-5</code></td><td>Claude Sonnet 4.5</td></tr>
|
| 214 |
-
<tr><td><code>claude-sonnet-4-5-thinking</code></td><td>Claude Sonnet 4.5
|
| 215 |
</table>
|
| 216 |
</div>
|
| 217 |
-
<div class="doc
|
| 218 |
<h3>API 端点</h3>
|
| 219 |
-
<table
|
| 220 |
<tr><td>POST</td><td><code>/v1/chat/completions</code></td><td>OpenAI Chat</td></tr>
|
| 221 |
<tr><td>POST</td><td><code>/v1/messages</code></td><td>Anthropic Messages</td></tr>
|
| 222 |
<tr><td>POST</td><td><code>/v1/responses</code></td><td>OpenAI Response API</td></tr>
|
| 223 |
-
<tr><td>GET</td><td><code>/v1/models</code></td><td>
|
| 224 |
</table>
|
| 225 |
</div>
|
| 226 |
-
<div class="doc
|
| 227 |
-
<h3>curl
|
| 228 |
<pre>curl -X POST https://your-host/v1/chat/completions \
|
| 229 |
-H "Authorization: Bearer YOUR_API_KEY" \
|
| 230 |
-H "Content-Type: application/json" \
|
|
@@ -234,32 +260,31 @@ pre{background:#1e1e2e;color:#cdd6f4;padding:14px;border-radius:6px;overflow-x:a
|
|
| 234 |
"stream": true
|
| 235 |
}'</pre>
|
| 236 |
</div>
|
| 237 |
-
<div class="doc
|
| 238 |
-
<h3>Python
|
| 239 |
<pre>from openai import OpenAI
|
| 240 |
|
| 241 |
-
client = OpenAI(api_key="
|
| 242 |
-
|
| 243 |
model="claude-opus-4-6",
|
| 244 |
messages=[{"role": "user", "content": "Hello!"}],
|
| 245 |
-
stream=True
|
| 246 |
-
)
|
| 247 |
-
for chunk in resp:
|
| 248 |
print(chunk.choices[0].delta.content or "", end="")</pre>
|
| 249 |
</div>
|
| 250 |
</div>
|
| 251 |
|
| 252 |
-
</div><
|
| 253 |
|
| 254 |
-
<!-- IMPORT
|
| 255 |
-
<div class="
|
| 256 |
-
<div class="
|
| 257 |
<h3>导入 Token</h3>
|
| 258 |
-
<
|
| 259 |
<textarea id="import-text" placeholder='{"email":"...","password":"...","jwt":"..."}'></textarea>
|
| 260 |
-
<div class="
|
| 261 |
-
<button class="
|
| 262 |
-
<button class="
|
| 263 |
</div>
|
| 264 |
</div>
|
| 265 |
</div>
|
|
@@ -267,137 +292,102 @@ for chunk in resp:
|
|
| 267 |
<div class="toast" id="toast"></div>
|
| 268 |
|
| 269 |
<script>
|
| 270 |
-
const
|
| 271 |
-
let tokens=[],filter='all',
|
| 272 |
|
| 273 |
-
async function api(p,o={}){const r=await fetch(
|
| 274 |
-
function toast(m,d=2500){const t=
|
| 275 |
-
function
|
| 276 |
-
function
|
|
|
|
| 277 |
|
| 278 |
-
|
| 279 |
|
| 280 |
async function doLogin(){
|
| 281 |
-
const
|
| 282 |
-
|
| 283 |
-
if(r.ok){showMain();load();loadConfig()}
|
| 284 |
-
else document.getElementById('login-err').style.display='block';
|
| 285 |
}
|
| 286 |
async function doLogout(){await api('/logout',{method:'POST'});showLogin()}
|
| 287 |
-
|
| 288 |
-
async function checkAuth(){
|
| 289 |
-
const r=await fetch(API+'/verify');
|
| 290 |
-
if(r.ok){showMain();load();loadConfig()}
|
| 291 |
-
}
|
| 292 |
checkAuth();
|
| 293 |
|
| 294 |
function showPage(p){
|
| 295 |
-
document.querySelectorAll('.page').forEach(
|
| 296 |
-
|
| 297 |
-
document.querySelectorAll('.
|
| 298 |
}
|
| 299 |
|
| 300 |
async function load(){
|
| 301 |
const r=await api('/tokens');if(!r)return;
|
| 302 |
-
const d=await r.json();
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
document.getElementById('s-usage').textContent=tokens.reduce((s,t)=>s+(t.use_count||0),0);
|
| 309 |
-
document.getElementById('fc-all').textContent=tot;
|
| 310 |
-
document.getElementById('fc-active').textContent=act;
|
| 311 |
-
document.getElementById('fc-inactive').textContent=inact;
|
| 312 |
-
currentPage=1;
|
| 313 |
-
render();
|
| 314 |
}
|
| 315 |
|
| 316 |
-
function
|
| 317 |
-
if(filter==='active')return tokens.filter(t=>t.is_active);
|
| 318 |
-
if(filter==='inactive')return tokens.filter(t=>!t.is_active);
|
| 319 |
-
return tokens;
|
| 320 |
-
}
|
| 321 |
|
| 322 |
function render(){
|
| 323 |
-
const
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
<span class="op-btn" title="${t.is_active?'停用':'启用'}" onclick="toggleOne(${t.id})">×</span>
|
| 341 |
-
<span class="op-btn" title="删除" onclick="deleteOne(${t.id})">🗑</span>
|
| 342 |
-
</td>
|
| 343 |
-
</tr>`}).join('');
|
| 344 |
-
document.getElementById('pager').innerHTML=list.length>pageSize?`
|
| 345 |
-
<button ${currentPage<=1?'disabled':''} onclick="goPage(${currentPage-1})">‹</button>
|
| 346 |
-
<span>第 ${currentPage}/${totalPages} 页 · 共 ${list.length} 条</span>
|
| 347 |
-
<button ${currentPage>=totalPages?'disabled':''} onclick="goPage(${currentPage+1})">›</button>`:'';
|
| 348 |
}
|
| 349 |
|
| 350 |
-
function
|
| 351 |
-
function setFilter(f){filter=f;
|
| 352 |
-
function
|
| 353 |
-
function toggleAll(c){
|
| 354 |
|
| 355 |
-
async function
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
load();
|
| 359 |
-
}
|
| 360 |
-
async function deleteOne(id){if(!confirm('确定删除?'))return;await api('/tokens/delete',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({ids:[id]})});load()}
|
| 361 |
-
async function refreshOne(id){toast('刷新中...');const r=await api('/tokens/refresh',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({ids:[id]})});if(r){const d=await r.json();toast(d.refreshed?'刷新成功':'刷新失败')}load()}
|
| 362 |
|
| 363 |
async function batchOp(action){
|
| 364 |
-
const ids=[...
|
| 365 |
-
if(action==='delete'&&!confirm(`
|
| 366 |
-
toast(`
|
| 367 |
const r=await api(`/tokens/${action}`,{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({ids})});
|
| 368 |
-
if(r){const d=await r.json();toast(JSON.stringify(d))}
|
| 369 |
-
selected.clear();load();
|
| 370 |
}
|
| 371 |
|
| 372 |
-
function openImport(){
|
| 373 |
-
function closeImport(){
|
| 374 |
async function doImport(){
|
| 375 |
-
const t=
|
| 376 |
-
if(!t){toast('请粘贴 JSONL 数据');return}
|
| 377 |
const r=await api('/tokens/import',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({jsonl:t})});
|
| 378 |
-
if(r){const d=await r.json();toast(`
|
| 379 |
-
}
|
| 380 |
-
async function doExport(){
|
| 381 |
-
const r=await api('/tokens/export');if(!r)return;
|
| 382 |
-
const b=await r.blob();const a=document.createElement('a');a.href=URL.createObjectURL(b);a.download='emergent_tokens.zip';a.click();
|
| 383 |
}
|
|
|
|
| 384 |
|
| 385 |
async function loadConfig(){
|
| 386 |
-
const r=await api('/config');if(!r)return;
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
document.getElementById('cfg-backend').value=d.backend||'jobs';
|
| 390 |
-
document.getElementById('cfg-proxy').value=d.proxy||'';
|
| 391 |
-
document.getElementById('cfg-admin_password').value=d.admin_password||'';
|
| 392 |
}
|
| 393 |
async function saveConfig(){
|
| 394 |
-
const b={api_key:
|
| 395 |
const r=await api('/config',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(b)});
|
| 396 |
-
if(r){const d=await r.json();toast(`
|
| 397 |
}
|
| 398 |
async function genKey(){
|
| 399 |
const r=await api('/config/generate-key',{method:'POST'});
|
| 400 |
-
if(r){const d=await r.json();
|
| 401 |
}
|
| 402 |
</script>
|
| 403 |
</body>
|
|
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
| 5 |
<title>Emergent2API</title>
|
| 6 |
+
<link rel="preconnect" href="https://fonts.googleapis.com">
|
| 7 |
+
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600&family=DM+Sans:wght@400;500;600;700&display=swap" rel="stylesheet">
|
| 8 |
<style>
|
| 9 |
+
:root{
|
| 10 |
+
--bg:#0d0d0d;--bg2:#161616;--bg3:#1c1c1c;--surface:#222;--surface2:#2a2a2a;
|
| 11 |
+
--border:#2e2e2e;--border2:#383838;
|
| 12 |
+
--text:#e8e8e8;--text2:#a0a0a0;--text3:#686868;
|
| 13 |
+
--accent:#c4703f;--accent2:#d4864f;
|
| 14 |
+
--green:#34d399;--green-bg:rgba(52,211,153,.1);
|
| 15 |
+
--red:#f87171;--red-bg:rgba(248,113,113,.1);
|
| 16 |
+
--blue:#60a5fa;
|
| 17 |
+
--radius:8px;--mono:'JetBrains Mono',monospace;--sans:'DM Sans',system-ui,sans-serif;
|
| 18 |
+
}
|
| 19 |
*{margin:0;padding:0;box-sizing:border-box}
|
| 20 |
+
body{font-family:var(--sans);background:var(--bg);color:var(--text);font-size:14px;line-height:1.5;-webkit-font-smoothing:antialiased}
|
| 21 |
+
::selection{background:var(--accent);color:#fff}
|
| 22 |
+
::-webkit-scrollbar{width:6px;height:6px}
|
| 23 |
+
::-webkit-scrollbar-track{background:transparent}
|
| 24 |
+
::-webkit-scrollbar-thumb{background:var(--border2);border-radius:3px}
|
| 25 |
+
|
| 26 |
+
/* ═══ LOGIN ═══ */
|
| 27 |
+
#view-login{display:flex;align-items:center;justify-content:center;min-height:100vh;background:var(--bg);position:relative;overflow:hidden}
|
| 28 |
+
#view-login::before{content:'';position:absolute;top:-40%;left:-20%;width:80%;height:80%;background:radial-gradient(ellipse,rgba(196,112,63,.06) 0%,transparent 70%);pointer-events:none}
|
| 29 |
+
.login-box{position:relative;z-index:1;width:380px;padding:48px 40px;background:var(--bg2);border:1px solid var(--border);border-radius:16px}
|
| 30 |
+
.login-logo{display:flex;align-items:center;gap:10px;margin-bottom:6px}
|
| 31 |
+
.login-logo svg{width:28px;height:28px;fill:var(--accent)}
|
| 32 |
+
.login-logo span{font-size:20px;font-weight:700;letter-spacing:-.3px}
|
| 33 |
+
.login-sub{color:var(--text3);font-size:13px;margin-bottom:32px}
|
| 34 |
+
.login-label{display:block;font-size:12px;font-weight:600;color:var(--text2);margin-bottom:6px;text-transform:uppercase;letter-spacing:.5px}
|
| 35 |
+
.login-input{width:100%;padding:11px 14px;background:var(--bg3);border:1px solid var(--border);border-radius:var(--radius);color:var(--text);font-size:14px;font-family:var(--sans);outline:none;transition:border .2s}
|
| 36 |
+
.login-input:focus{border-color:var(--accent)}
|
| 37 |
+
.login-input::placeholder{color:var(--text3)}
|
| 38 |
+
.login-btn{width:100%;margin-top:20px;padding:11px;background:var(--accent);color:#fff;border:none;border-radius:var(--radius);font-size:14px;font-weight:600;font-family:var(--sans);cursor:pointer;transition:background .15s}
|
| 39 |
+
.login-btn:hover{background:var(--accent2)}
|
| 40 |
+
.login-err{color:var(--red);font-size:12px;text-align:center;margin-top:12px;display:none}
|
| 41 |
+
|
| 42 |
+
/* ═══ SHELL ═══ */
|
| 43 |
+
#view-main{display:none}
|
| 44 |
+
.topbar{height:48px;background:var(--bg2);border-bottom:1px solid var(--border);display:flex;align-items:center;padding:0 20px;position:sticky;top:0;z-index:100}
|
| 45 |
+
.topbar-brand{font-weight:700;font-size:15px;color:var(--text);margin-right:24px;display:flex;align-items:center;gap:8px}
|
| 46 |
+
.topbar-brand svg{width:20px;height:20px;fill:var(--accent)}
|
| 47 |
+
.tabs{display:flex;gap:0;height:100%}
|
| 48 |
+
.tab{display:flex;align-items:center;padding:0 16px;font-size:13px;font-weight:500;color:var(--text3);cursor:pointer;border-bottom:2px solid transparent;transition:color .15s}
|
| 49 |
+
.tab:hover{color:var(--text2)}
|
| 50 |
+
.tab.on{color:var(--accent);border-bottom-color:var(--accent)}
|
| 51 |
+
.topbar-r{margin-left:auto;display:flex;align-items:center;gap:4px}
|
| 52 |
+
.topbar-r button{background:none;border:none;color:var(--text3);font-size:13px;font-family:var(--sans);cursor:pointer;padding:6px 10px;border-radius:6px;transition:.15s}
|
| 53 |
+
.topbar-r button:hover{color:var(--red);background:var(--red-bg)}
|
| 54 |
+
|
| 55 |
+
.main{max-width:1080px;margin:0 auto;padding:28px 24px}
|
| 56 |
+
.page{display:none}.page.on{display:block}
|
| 57 |
+
|
| 58 |
+
/* ═══ SECTION HEADER ═══ */
|
| 59 |
+
.sec-head{display:flex;align-items:baseline;gap:12px;margin-bottom:20px}
|
| 60 |
+
.sec-title{font-size:20px;font-weight:700;letter-spacing:-.3px}
|
| 61 |
+
.sec-sub{font-size:13px;color:var(--text3)}
|
| 62 |
+
|
| 63 |
+
/* ═══ STATS ═══ */
|
| 64 |
+
.stats{display:grid;grid-template-columns:repeat(4,1fr);gap:10px;margin-bottom:22px}
|
| 65 |
+
.st{background:var(--bg2);border:1px solid var(--border);border-radius:var(--radius);padding:16px 18px}
|
| 66 |
+
.st-v{font-size:28px;font-weight:700;font-family:var(--mono);letter-spacing:-.5px}
|
| 67 |
+
.st-v.g{color:var(--green)}.st-v.r{color:var(--red)}.st-v.o{color:var(--accent)}
|
| 68 |
+
.st-l{font-size:11px;color:var(--text3);margin-top:4px;text-transform:uppercase;letter-spacing:.5px}
|
| 69 |
+
|
| 70 |
+
/* ═══ TOOLBAR ═══ */
|
| 71 |
+
.toolbar{display:flex;align-items:center;gap:6px;margin-bottom:14px;flex-wrap:wrap}
|
| 72 |
+
.pill{padding:5px 12px;border:1px solid var(--border);border-radius:20px;font-size:12px;font-weight:500;color:var(--text3);background:transparent;cursor:pointer;transition:.15s;font-family:var(--sans)}
|
| 73 |
+
.pill:hover{border-color:var(--text3);color:var(--text2)}
|
| 74 |
+
.pill.on{background:var(--accent);border-color:var(--accent);color:#fff}
|
| 75 |
+
.pill b{font-weight:600;margin-left:3px}
|
| 76 |
+
.sep{flex:1}
|
| 77 |
+
.tbtn{padding:6px 14px;border:1px solid var(--border);border-radius:6px;font-size:12px;font-weight:500;cursor:pointer;background:var(--bg2);color:var(--text2);font-family:var(--sans);transition:.15s}
|
| 78 |
+
.tbtn:hover{border-color:var(--text3);color:var(--text)}
|
| 79 |
+
.tbtn.accent{background:var(--accent);border-color:var(--accent);color:#fff}
|
| 80 |
+
.tbtn.accent:hover{background:var(--accent2)}
|
| 81 |
+
.tbtn.red{background:transparent;border-color:var(--red);color:var(--red)}
|
| 82 |
+
.tbtn.red:hover{background:var(--red-bg)}
|
| 83 |
+
.tbtn.green{background:transparent;border-color:var(--green);color:var(--green)}
|
| 84 |
+
.tbtn.green:hover{background:var(--green-bg)}
|
| 85 |
+
|
| 86 |
+
/* ═══ TABLE ═══ */
|
| 87 |
+
.tbl-wrap{background:var(--bg2);border:1px solid var(--border);border-radius:var(--radius);overflow-x:auto}
|
| 88 |
+
table{width:100%;border-collapse:collapse;min-width:680px}
|
| 89 |
+
th{text-align:left;padding:10px 14px;font-size:11px;font-weight:600;color:var(--text3);text-transform:uppercase;letter-spacing:.5px;border-bottom:1px solid var(--border);background:var(--bg3)}
|
| 90 |
+
td{padding:9px 14px;font-size:13px;border-bottom:1px solid var(--border)}
|
| 91 |
tr:last-child td{border-bottom:none}
|
| 92 |
+
tr:hover td{background:rgba(255,255,255,.02)}
|
| 93 |
+
.mono{font-family:var(--mono);font-size:12px;color:var(--text2)}
|
| 94 |
+
.badge{display:inline-flex;align-items:center;gap:4px;padding:3px 10px;border-radius:4px;font-size:11px;font-weight:600;font-family:var(--mono)}
|
| 95 |
+
.badge::before{content:'';width:6px;height:6px;border-radius:50%}
|
| 96 |
+
.badge-g{background:var(--green-bg);color:var(--green)}.badge-g::before{background:var(--green)}
|
| 97 |
+
.badge-r{background:var(--red-bg);color:var(--red)}.badge-r::before{background:var(--red)}
|
| 98 |
+
.ops{display:flex;gap:4px}
|
| 99 |
+
.op{width:28px;height:28px;border:1px solid var(--border);border-radius:5px;background:transparent;color:var(--text3);cursor:pointer;display:flex;align-items:center;justify-content:center;font-size:13px;transition:.12s}
|
| 100 |
+
.op:hover{border-color:var(--text3);color:var(--text);background:var(--surface)}
|
| 101 |
+
.op.del:hover{border-color:var(--red);color:var(--red);background:var(--red-bg)}
|
| 102 |
+
.chk{width:15px;height:15px;accent-color:var(--accent);cursor:pointer}
|
| 103 |
+
.pager{display:flex;align-items:center;justify-content:center;gap:8px;padding:12px;font-size:12px;color:var(--text3)}
|
| 104 |
+
.pager button{padding:4px 10px;border:1px solid var(--border);border-radius:4px;background:var(--bg3);color:var(--text2);cursor:pointer;font-size:11px;font-family:var(--sans)}
|
| 105 |
+
.pager button:hover{border-color:var(--text3)}
|
| 106 |
+
.pager button:disabled{opacity:.3;cursor:default}
|
| 107 |
+
|
| 108 |
+
/* ═══ MODAL ═══ */
|
| 109 |
+
.overlay{display:none;position:fixed;inset:0;background:rgba(0,0,0,.6);z-index:200;align-items:center;justify-content:center;backdrop-filter:blur(4px)}
|
| 110 |
+
.overlay.open{display:flex}
|
| 111 |
+
.dialog{background:var(--bg2);border:1px solid var(--border);border-radius:14px;padding:28px;width:480px;max-height:80vh;overflow-y:auto}
|
| 112 |
+
.dialog h3{font-size:16px;font-weight:700;margin-bottom:4px}
|
| 113 |
+
.dialog .sub{font-size:12px;color:var(--text3);margin-bottom:14px}
|
| 114 |
+
.dialog textarea{width:100%;height:180px;padding:12px;background:var(--bg3);border:1px solid var(--border);border-radius:6px;color:var(--text);font-family:var(--mono);font-size:12px;resize:vertical;outline:none}
|
| 115 |
+
.dialog textarea:focus{border-color:var(--accent)}
|
| 116 |
+
.dialog-foot{display:flex;gap:8px;justify-content:flex-end;margin-top:16px}
|
| 117 |
+
|
| 118 |
+
/* ═══ CONFIG ═══ */
|
| 119 |
+
.card{background:var(--bg2);border:1px solid var(--border);border-radius:var(--radius);padding:24px;margin-bottom:14px}
|
| 120 |
+
.card h3{font-size:14px;font-weight:700;margin-bottom:16px;padding-bottom:12px;border-bottom:1px solid var(--border);text-transform:uppercase;letter-spacing:.3px;color:var(--text2)}
|
| 121 |
+
.fld{margin-bottom:14px}
|
| 122 |
+
.fld label{display:block;font-size:12px;font-weight:600;color:var(--text3);margin-bottom:5px;letter-spacing:.3px}
|
| 123 |
+
.fld input,.fld select{width:100%;padding:9px 13px;background:var(--bg3);border:1px solid var(--border);border-radius:6px;color:var(--text);font-size:13px;font-family:var(--sans);outline:none;transition:border .15s}
|
| 124 |
+
.fld input:focus,.fld select:focus{border-color:var(--accent)}
|
| 125 |
+
.fld select{appearance:none;background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23686868' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");background-repeat:no-repeat;background-position:right 12px center}
|
| 126 |
+
.fld .hint{font-size:11px;color:var(--text3);margin-top:4px}
|
| 127 |
+
.fld-row{display:flex;gap:10px;align-items:end}
|
| 128 |
+
.fld-row .fld{flex:1}
|
| 129 |
+
|
| 130 |
+
/* ═══ DOCS ═══ */
|
| 131 |
+
.doc{background:var(--bg2);border:1px solid var(--border);border-radius:var(--radius);padding:24px;margin-bottom:14px}
|
| 132 |
+
.doc h3{font-size:14px;font-weight:700;color:var(--accent);margin-bottom:10px}
|
| 133 |
+
.doc p{font-size:13px;color:var(--text2);margin-bottom:6px}
|
| 134 |
+
.doc pre{background:var(--bg);border:1px solid var(--border);padding:16px;border-radius:6px;font-family:var(--mono);font-size:12px;color:var(--text2);overflow-x:auto;line-height:1.6;margin:8px 0 10px}
|
| 135 |
+
.doc table{width:100%;border-collapse:collapse;font-size:13px;margin:6px 0 8px}
|
| 136 |
+
.doc th{text-align:left;padding:7px 12px;font-size:11px;font-weight:600;color:var(--text3);text-transform:uppercase;letter-spacing:.4px;border-bottom:1px solid var(--border);background:var(--bg3)}
|
| 137 |
+
.doc td{padding:7px 12px;border-bottom:1px solid var(--border);color:var(--text2)}
|
| 138 |
+
.doc code{background:var(--bg);padding:2px 6px;border-radius:3px;font-family:var(--mono);font-size:12px;color:var(--accent)}
|
| 139 |
+
|
| 140 |
+
/* ═══ TOAST ═══ */
|
| 141 |
+
.toast{position:fixed;bottom:20px;right:20px;background:var(--surface2);border:1px solid var(--border2);color:var(--text);padding:10px 18px;border-radius:8px;font-size:13px;z-index:300;opacity:0;transition:opacity .2s;pointer-events:none}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
.toast.show{opacity:1}
|
| 143 |
|
| 144 |
+
@media(max-width:768px){.stats{grid-template-columns:repeat(2,1fr)}.main{padding:16px}}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
</style>
|
| 146 |
</head>
|
| 147 |
<body>
|
| 148 |
|
| 149 |
+
<div id="view-login">
|
| 150 |
+
<div class="login-box">
|
| 151 |
+
<div class="login-logo">
|
| 152 |
+
<svg viewBox="0 0 24 24"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 17.93c-3.95-.49-7-3.85-7-7.93 0-.62.08-1.21.21-1.79L9 15v1c0 1.1.9 2 2 2v1.93zm6.9-2.54c-.26-.81-1-1.39-1.9-1.39h-1v-3c0-.55-.45-1-1-1H8v-2h2c.55 0 1-.45 1-1V7h2c1.1 0 2-.9 2-2v-.41c2.93 1.19 5 4.06 5 7.41 0 2.08-.8 3.97-2.1 5.39z"/></svg>
|
| 153 |
+
<span>Emergent2API</span>
|
| 154 |
+
</div>
|
| 155 |
+
<div class="login-sub">Admin Console</div>
|
| 156 |
+
<label class="login-label">Password</label>
|
| 157 |
+
<input type="password" id="pwd" class="login-input" placeholder="Enter admin password" autofocus>
|
| 158 |
+
<button class="login-btn" onclick="doLogin()">Sign In</button>
|
| 159 |
+
<div class="login-err" id="login-err">Invalid password</div>
|
| 160 |
+
</div>
|
| 161 |
</div>
|
| 162 |
|
| 163 |
+
<div id="view-main">
|
| 164 |
+
<div class="topbar">
|
| 165 |
+
<div class="topbar-brand">
|
| 166 |
+
<svg viewBox="0 0 24 24"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 17.93c-3.95-.49-7-3.85-7-7.93 0-.62.08-1.21.21-1.79L9 15v1c0 1.1.9 2 2 2v1.93zm6.9-2.54c-.26-.81-1-1.39-1.9-1.39h-1v-3c0-.55-.45-1-1-1H8v-2h2c.55 0 1-.45 1-1V7h2c1.1 0 2-.9 2-2v-.41c2.93 1.19 5 4.06 5 7.41 0 2.08-.8 3.97-2.1 5.39z"/></svg>
|
| 167 |
+
Emergent2API
|
|
|
|
|
|
|
|
|
|
| 168 |
</div>
|
| 169 |
+
<div class="tabs">
|
| 170 |
+
<div class="tab on" data-p="tokens" onclick="showPage('tokens')">Token 管理</div>
|
| 171 |
+
<div class="tab" data-p="config" onclick="showPage('config')">配置管理</div>
|
| 172 |
+
<div class="tab" data-p="docs" onclick="showPage('docs')">使用文档</div>
|
| 173 |
</div>
|
| 174 |
+
<div class="topbar-r"><button onclick="doLogout()">退出</button></div>
|
| 175 |
+
</div>
|
| 176 |
+
|
| 177 |
+
<div class="main">
|
| 178 |
|
| 179 |
+
<!-- ─── TOKENS ─── -->
|
| 180 |
+
<div id="p-tokens" class="page on">
|
| 181 |
+
<div class="sec-head"><span class="sec-title">Token 列表</span><span class="sec-sub">管理 Emergent 服务号池</span></div>
|
|
|
|
| 182 |
<div class="stats">
|
| 183 |
+
<div class="st"><div class="st-v" id="s-total">0</div><div class="st-l">Total</div></div>
|
| 184 |
+
<div class="st"><div class="st-v g" id="s-active">0</div><div class="st-l">Active</div></div>
|
| 185 |
+
<div class="st"><div class="st-v r" id="s-inactive">0</div><div class="st-l">Inactive</div></div>
|
| 186 |
+
<div class="st"><div class="st-v o" id="s-usage">0</div><div class="st-l">Requests</div></div>
|
| 187 |
</div>
|
| 188 |
+
<div class="toolbar">
|
| 189 |
+
<button class="pill on" data-f="all" onclick="setFilter('all')">全部<b id="fc-all">0</b></button>
|
| 190 |
+
<button class="pill" data-f="active" onclick="setFilter('active')">正常<b id="fc-active">0</b></button>
|
| 191 |
+
<button class="pill" data-f="inactive" onclick="setFilter('inactive')">失效<b id="fc-inactive">0</b></button>
|
| 192 |
+
<span class="sep"></span>
|
| 193 |
+
<button class="tbtn" onclick="openImport()">↑ 导入</button>
|
| 194 |
+
<button class="tbtn" onclick="doExport()">↓ 导出</button>
|
| 195 |
+
<button class="tbtn green" onclick="batchOp('test')">⟳ 测试</button>
|
| 196 |
+
<button class="tbtn red" onclick="batchOp('delete')">✕ 删除</button>
|
| 197 |
</div>
|
| 198 |
+
<div class="tbl-wrap">
|
| 199 |
+
<table><thead><tr>
|
| 200 |
+
<th style="width:36px"><input type="checkbox" class="chk" id="chk-all" onchange="toggleAll(this.checked)"></th>
|
| 201 |
+
<th>Email</th><th>状态</th><th>余额</th><th>最后使用</th><th>操作</th>
|
| 202 |
+
</tr></thead><tbody id="tbody"></tbody></table>
|
| 203 |
+
<div class="pager" id="pager"></div>
|
|
|
|
|
|
|
|
|
|
| 204 |
</div>
|
| 205 |
</div>
|
| 206 |
|
| 207 |
+
<!-- ─── CONFIG ─── -->
|
| 208 |
+
<div id="p-config" class="page">
|
| 209 |
+
<div class="sec-head"><span class="sec-title">配置管理</span><span class="sec-sub">API 密钥与后端设置</span></div>
|
| 210 |
+
<div class="card">
|
| 211 |
+
<h3>API Settings</h3>
|
| 212 |
+
<div class="fld-row">
|
| 213 |
+
<div class="fld"><label>API Key</label><input id="cfg-api_key" placeholder="sk-..." spellcheck="false"></div>
|
| 214 |
+
<div style="padding-bottom:14px"><button class="tbtn accent" onclick="genKey()">生成</button></div>
|
|
|
|
| 215 |
</div>
|
| 216 |
+
<div class="fld">
|
| 217 |
+
<label>Backend</label>
|
| 218 |
+
<select id="cfg-backend"><option value="jobs">Jobs API(无 IP 限制)</option><option value="integrations">Integrations API(更快,需代理)</option></select>
|
| 219 |
</div>
|
| 220 |
+
<div class="fld"><label>Proxy</label><input id="cfg-proxy" placeholder="http://user:pass@host:port" spellcheck="false"><div class="hint">Integrations 后端必填;Jobs 可选</div></div>
|
| 221 |
</div>
|
| 222 |
+
<div class="card">
|
| 223 |
+
<h3>Admin</h3>
|
| 224 |
+
<div class="fld"><label>Password</label><input id="cfg-admin_password" type="password"></div>
|
| 225 |
</div>
|
| 226 |
<div style="display:flex;gap:8px;justify-content:flex-end">
|
| 227 |
+
<button class="tbtn" onclick="loadConfig()">重置</button>
|
| 228 |
+
<button class="tbtn accent" onclick="saveConfig()">保存</button>
|
| 229 |
</div>
|
| 230 |
</div>
|
| 231 |
|
| 232 |
+
<!-- ─── DOCS ─── -->
|
| 233 |
+
<div id="p-docs" class="page">
|
| 234 |
+
<div class="sec-head"><span class="sec-title">使用文档</span><span class="sec-sub">API 端点与接入指南</span></div>
|
| 235 |
+
<div class="doc">
|
|
|
|
| 236 |
<h3>可用模型</h3>
|
| 237 |
+
<table><tr><th>Model ID</th><th>Description</th></tr>
|
| 238 |
+
<tr><td><code>claude-opus-4-6</code></td><td>Claude Opus 4.6 — full, uncapped</td></tr>
|
| 239 |
<tr><td><code>claude-sonnet-4-5</code></td><td>Claude Sonnet 4.5</td></tr>
|
| 240 |
+
<tr><td><code>claude-sonnet-4-5-thinking</code></td><td>Claude Sonnet 4.5 — extended thinking</td></tr>
|
| 241 |
</table>
|
| 242 |
</div>
|
| 243 |
+
<div class="doc">
|
| 244 |
<h3>API 端点</h3>
|
| 245 |
+
<table><tr><th>Method</th><th>Endpoint</th><th>Format</th></tr>
|
| 246 |
<tr><td>POST</td><td><code>/v1/chat/completions</code></td><td>OpenAI Chat</td></tr>
|
| 247 |
<tr><td>POST</td><td><code>/v1/messages</code></td><td>Anthropic Messages</td></tr>
|
| 248 |
<tr><td>POST</td><td><code>/v1/responses</code></td><td>OpenAI Response API</td></tr>
|
| 249 |
+
<tr><td>GET</td><td><code>/v1/models</code></td><td>Model list</td></tr>
|
| 250 |
</table>
|
| 251 |
</div>
|
| 252 |
+
<div class="doc">
|
| 253 |
+
<h3>curl</h3>
|
| 254 |
<pre>curl -X POST https://your-host/v1/chat/completions \
|
| 255 |
-H "Authorization: Bearer YOUR_API_KEY" \
|
| 256 |
-H "Content-Type: application/json" \
|
|
|
|
| 260 |
"stream": true
|
| 261 |
}'</pre>
|
| 262 |
</div>
|
| 263 |
+
<div class="doc">
|
| 264 |
+
<h3>Python — OpenAI SDK</h3>
|
| 265 |
<pre>from openai import OpenAI
|
| 266 |
|
| 267 |
+
client = OpenAI(api_key="YOUR_KEY", base_url="https://your-host/v1")
|
| 268 |
+
for chunk in client.chat.completions.create(
|
| 269 |
model="claude-opus-4-6",
|
| 270 |
messages=[{"role": "user", "content": "Hello!"}],
|
| 271 |
+
stream=True,
|
| 272 |
+
):
|
|
|
|
| 273 |
print(chunk.choices[0].delta.content or "", end="")</pre>
|
| 274 |
</div>
|
| 275 |
</div>
|
| 276 |
|
| 277 |
+
</div></div>
|
| 278 |
|
| 279 |
+
<!-- ─── IMPORT DIALOG ─── -->
|
| 280 |
+
<div class="overlay" id="dlg-import">
|
| 281 |
+
<div class="dialog">
|
| 282 |
<h3>导入 Token</h3>
|
| 283 |
+
<div class="sub">粘贴 JSONL — 每行一个账号(email, password, jwt 必填)</div>
|
| 284 |
<textarea id="import-text" placeholder='{"email":"...","password":"...","jwt":"..."}'></textarea>
|
| 285 |
+
<div class="dialog-foot">
|
| 286 |
+
<button class="tbtn" onclick="closeImport()">取消</button>
|
| 287 |
+
<button class="tbtn accent" onclick="doImport()">导入</button>
|
| 288 |
</div>
|
| 289 |
</div>
|
| 290 |
</div>
|
|
|
|
| 292 |
<div class="toast" id="toast"></div>
|
| 293 |
|
| 294 |
<script>
|
| 295 |
+
const A='/v1/admin';
|
| 296 |
+
let tokens=[],filter='all',sel=new Set(),pg=1,PS=50;
|
| 297 |
|
| 298 |
+
async function api(p,o={}){const r=await fetch(A+p,o);if(r.status===401){showLogin();return null}return r}
|
| 299 |
+
function toast(m,d=2500){const t=$('toast');t.textContent=m;t.classList.add('show');setTimeout(()=>t.classList.remove('show'),d)}
|
| 300 |
+
function $(id){return document.getElementById(id)}
|
| 301 |
+
function showLogin(){$('view-login').style.display='';$('view-main').style.display='none'}
|
| 302 |
+
function showMain(){$('view-login').style.display='none';$('view-main').style.display=''}
|
| 303 |
|
| 304 |
+
$('pwd').addEventListener('keydown',e=>{if(e.key==='Enter')doLogin()});
|
| 305 |
|
| 306 |
async function doLogin(){
|
| 307 |
+
const r=await fetch(A+'/login',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({password:$('pwd').value})});
|
| 308 |
+
if(r.ok){showMain();load();loadConfig()}else $('login-err').style.display='block';
|
|
|
|
|
|
|
| 309 |
}
|
| 310 |
async function doLogout(){await api('/logout',{method:'POST'});showLogin()}
|
| 311 |
+
async function checkAuth(){const r=await fetch(A+'/verify');if(r.ok){showMain();load();loadConfig()}}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 312 |
checkAuth();
|
| 313 |
|
| 314 |
function showPage(p){
|
| 315 |
+
document.querySelectorAll('.page').forEach(e=>e.classList.remove('on'));
|
| 316 |
+
$(('p-'+p)).classList.add('on');
|
| 317 |
+
document.querySelectorAll('.tab').forEach(e=>e.classList.toggle('on',e.dataset.p===p));
|
| 318 |
}
|
| 319 |
|
| 320 |
async function load(){
|
| 321 |
const r=await api('/tokens');if(!r)return;
|
| 322 |
+
const d=await r.json();tokens=d.tokens||[];
|
| 323 |
+
const act=d.active,tot=d.total,ina=tot-act;
|
| 324 |
+
$('s-total').textContent=tot;$('s-active').textContent=act;$('s-inactive').textContent=ina;
|
| 325 |
+
$('s-usage').textContent=tokens.reduce((s,t)=>s+(t.use_count||0),0);
|
| 326 |
+
$('fc-all').textContent=tot;$('fc-active').textContent=act;$('fc-inactive').textContent=ina;
|
| 327 |
+
pg=1;render();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 328 |
}
|
| 329 |
|
| 330 |
+
function filtered(){return filter==='active'?tokens.filter(t=>t.is_active):filter==='inactive'?tokens.filter(t=>!t.is_active):tokens}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 331 |
|
| 332 |
function render(){
|
| 333 |
+
const ls=filtered(),tp=Math.max(1,Math.ceil(ls.length/PS));
|
| 334 |
+
if(pg>tp)pg=tp;
|
| 335 |
+
const s=(pg-1)*PS,rows=ls.slice(s,s+PS);
|
| 336 |
+
$('tbody').innerHTML=rows.map(t=>{
|
| 337 |
+
const e=t.email||'',sh=e.length>30?e.slice(0,14)+'…'+e.slice(-12):e;
|
| 338 |
+
return`<tr>
|
| 339 |
+
<td><input type="checkbox" class="chk" data-id="${t.id}" ${sel.has(t.id)?'checked':''} onchange="tSel(${t.id},this.checked)"></td>
|
| 340 |
+
<td class="mono" title="${e}">${sh}</td>
|
| 341 |
+
<td><span class="badge ${t.is_active?'badge-g':'badge-r'}">${t.is_active?'active':'inactive'}</span></td>
|
| 342 |
+
<td style="color:var(--text2)">$${(t.balance||0).toFixed(2)}</td>
|
| 343 |
+
<td style="color:var(--text3);font-size:12px">${t.last_used?new Date(t.last_used).toLocaleString('zh-CN'):'-'}</td>
|
| 344 |
+
<td class="ops">
|
| 345 |
+
<button class="op" title="Refresh JWT" onclick="rOne(${t.id})">↻</button>
|
| 346 |
+
<button class="op" title="${t.is_active?'Disable':'Enable'}" onclick="tOne(${t.id})">⏻</button>
|
| 347 |
+
<button class="op del" title="Delete" onclick="dOne(${t.id})">✕</button>
|
| 348 |
+
</td></tr>`}).join('');
|
| 349 |
+
$('pager').innerHTML=ls.length>PS?`<button ${pg<=1?'disabled':''} onclick="goPg(${pg-1})">‹ Prev</button><span>Page ${pg} / ${tp} · ${ls.length} total</span><button ${pg>=tp?'disabled':''} onclick="goPg(${pg+1})">Next ›</button>`:'';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 350 |
}
|
| 351 |
|
| 352 |
+
function goPg(p){pg=p;render()}
|
| 353 |
+
function setFilter(f){filter=f;pg=1;document.querySelectorAll('.pill').forEach(e=>e.classList.toggle('on',e.dataset.f===f));render()}
|
| 354 |
+
function tSel(id,c){if(c)sel.add(id);else sel.delete(id)}
|
| 355 |
+
function toggleAll(c){filtered().slice((pg-1)*PS,pg*PS).forEach(t=>{if(c)sel.add(t.id);else sel.delete(t.id)});render()}
|
| 356 |
|
| 357 |
+
async function tOne(id){const t=tokens.find(x=>x.id===id);if(!t)return;await api('/tokens/toggle',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({ids:[id],active:!t.is_active})});load()}
|
| 358 |
+
async function dOne(id){if(!confirm('Delete this token?'))return;await api('/tokens/delete',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({ids:[id]})});load()}
|
| 359 |
+
async function rOne(id){toast('Refreshing…');const r=await api('/tokens/refresh',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({ids:[id]})});if(r){const d=await r.json();toast(d.refreshed?'Refreshed':'Failed')}load()}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 360 |
|
| 361 |
async function batchOp(action){
|
| 362 |
+
const ids=[...sel];if(!ids.length){toast('Select tokens first');return}
|
| 363 |
+
if(action==='delete'&&!confirm(`Delete ${ids.length} tokens?`))return;
|
| 364 |
+
toast(`Processing ${ids.length}…`);
|
| 365 |
const r=await api(`/tokens/${action}`,{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({ids})});
|
| 366 |
+
if(r){const d=await r.json();toast(JSON.stringify(d))}sel.clear();load();
|
|
|
|
| 367 |
}
|
| 368 |
|
| 369 |
+
function openImport(){$('dlg-import').classList.add('open')}
|
| 370 |
+
function closeImport(){$('dlg-import').classList.remove('open')}
|
| 371 |
async function doImport(){
|
| 372 |
+
const t=$('import-text').value.trim();if(!t){toast('Paste JSONL data');return}
|
|
|
|
| 373 |
const r=await api('/tokens/import',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({jsonl:t})});
|
| 374 |
+
if(r){const d=await r.json();toast(`Imported ${d.imported}`+(d.errors.length?`, ${d.errors.length} errors`:''));closeImport();load()}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 375 |
}
|
| 376 |
+
async function doExport(){const r=await api('/tokens/export');if(!r)return;const b=await r.blob();const a=document.createElement('a');a.href=URL.createObjectURL(b);a.download='emergent_tokens.zip';a.click()}
|
| 377 |
|
| 378 |
async function loadConfig(){
|
| 379 |
+
const r=await api('/config');if(!r)return;const d=await r.json();
|
| 380 |
+
$('cfg-api_key').value=d.api_key||'';$('cfg-backend').value=d.backend||'jobs';
|
| 381 |
+
$('cfg-proxy').value=d.proxy||'';$('cfg-admin_password').value=d.admin_password||'';
|
|
|
|
|
|
|
|
|
|
| 382 |
}
|
| 383 |
async function saveConfig(){
|
| 384 |
+
const b={api_key:$('cfg-api_key').value,backend:$('cfg-backend').value,proxy:$('cfg-proxy').value,admin_password:$('cfg-admin_password').value};
|
| 385 |
const r=await api('/config',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(b)});
|
| 386 |
+
if(r){const d=await r.json();toast(`Saved: ${d.saved.join(', ')}`)}
|
| 387 |
}
|
| 388 |
async function genKey(){
|
| 389 |
const r=await api('/config/generate-key',{method:'POST'});
|
| 390 |
+
if(r){const d=await r.json();$('cfg-api_key').value=d.api_key;toast('Key generated')}
|
| 391 |
}
|
| 392 |
</script>
|
| 393 |
</body>
|