File size: 22,785 Bytes
eb07461 |
1 2 3 4 5 6 7 8 9 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 56 57 58 59 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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 |
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>Grok Token 管理面板</title>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600&display=swap" rel="stylesheet">
<style>
:root {
--bg-primary: #f4f6f9;
--card-bg: #ffffff;
--text-primary: #2c3e50;
--text-secondary: #6c757d;
--border-color: #e2e8f0;
--primary-color: #3498db;
--success-color: #4caf50;
--danger-color: #f44336;
--warning-color: #ff9800;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: 'Inter', sans-serif;
background-color: var(--bg-primary);
color: var(--text-primary);
line-height: 1.6;
}
.container { max-width: 1400px; margin: 0 auto; padding: 20px; }
.search-section { margin-bottom: 20px; }
#searchInput { width: 100%; padding: 10px; border: 1px solid var(--border-color); border-radius: 8px; font-size: 16px; }
.overview-panel {
background-color: var(--card-bg);
border-radius: 16px;
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.08);
padding: 25px;
margin-bottom: 25px;
}
.header-actions {
display: flex;
justify-content: space-between;
align-items: center;
}
.overview-stats {
display: flex;
justify-content: stretch;
align-items: center;
width: 100%;
}
.model-remaining-stats {
display: flex;
gap: 30px;
flex-wrap: wrap;
justify-content: flex-end;
}
.model-stat {
display: flex;
flex-direction: column;
align-items: center;
}
.model-stat .stat-label {
font-size: 12px;
color: var(--text-secondary);
margin-bottom: 5px;
}
.model-stat .stat-value {
font-size: 16px;
font-weight: 600;
color: var(--primary-color);
min-width: 40px;
text-align: center;
}
.stat-item { text-align: center; }
.stat-value { font-size: 28px; font-weight: 600; color: var(--primary-color); }
.stat-label { font-size: 14px; color: var(--text-secondary); }
.refresh-icon {
cursor: pointer;
transition: transform 0.3s;
}
.refresh-icon:hover {
transform: rotate(180deg);
}
.token-management-section {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
margin-bottom: 25px;
}
.token-management-section > div {
background-color: var(--card-bg);
border-radius: 16px;
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.08);
padding: 25px;
}
.token-management-section h3 {
margin-bottom: 15px;
font-size: 16px;
color: var(--text-secondary);
}
.token-input-section { display: flex; gap: 15px; }
#tokenInput, #cfInput {
flex-grow: 1;
padding: 12px 15px;
border: 1px solid var(--border-color);
border-radius: 8px;
font-size: 16px;
}
#addTokenBtn, #setCfBtn {
padding: 12px 25px;
background-color: var(--primary-color);
color: white;
border: none;
border-radius: 8px;
cursor: pointer;
transition: background-color 0.3s;
}
#addTokenBtn:hover, #setCfBtn:hover { background-color: #2980b9; }
.token-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
gap: 20px;
}
.token-card {
background-color: var(--card-bg);
border-radius: 16px;
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
padding: 20px;
transition: transform 0.3s;
}
.token-card:hover { transform: translateY(-5px); }
.token-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 15px;
padding-bottom: 10px;
border-bottom: 1px solid var(--border-color);
}
.token-title {
font-size: 14px;
font-weight: 500;
max-width: 250px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.delete-btn {
background-color: var(--danger-color);
color: white;
border: none;
padding: 5px 10px;
border-radius: 4px;
cursor: pointer;
font-size: 12px;
}
.delete-btn:hover { background-color: #c0392b; }
.model-row {
display: flex;
align-items: center;
margin-bottom: 10px;
gap: 15px;
}
.model-name {
flex: 2;
font-size: 14px;
color: var(--text-secondary);
}
.progress-container {
flex: 6;
display: flex;
align-items: center;
gap: 10px;
}
.progress-bar {
flex-grow: 1;
height: 8px;
background-color: #e0e0e0;
border-radius: 4px;
overflow: hidden;
}
.progress-bar-fill {
height: 100%;
transition: width 0.5s ease;
}
.progress-text {
font-size: 12px;
color: var(--text-secondary);
min-width: 50px;
text-align: right;
}
.status-badge {
font-size: 12px;
padding: 3px 8px;
border-radius: 12px;
font-weight: 600;
position: relative;
cursor: help;
}
.status-badge .tooltip {
visibility: hidden;
position: absolute;
z-index: 1;
bottom: 125%;
left: 50%;
transform: translateX(-50%);
background-color: rgba(0, 0, 0, 0.8);
color: white;
text-align: center;
border-radius: 6px;
padding: 5px 10px;
opacity: 0;
transition: opacity 0.3s;
white-space: nowrap;
}
.status-badge:hover .tooltip {
visibility: visible;
opacity: 1;
}
.status-badge::after {
content: '';
position: absolute;
bottom: 100%;
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: transparent transparent rgba(0, 0, 0, 0.8) transparent;
opacity: 0;
transition: opacity 0.3s;
}
.status-badge:hover::after { opacity: 1; }
.status-active {
background-color: rgba(76, 175, 80, 0.1);
color: var(--success-color);
}
.status-expired {
background-color: rgba(244, 67, 54, 0.1);
color: var(--danger-color);
}
#notification {
position: fixed;
top: 20px;
left: 50%;
transform: translateX(-50%);
background-color: #3498db;
color: white;
padding: 10px 20px;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0,0,0,0.2);
display: none;
z-index: 1000;
}
</style>
</head>
<body>
<div class="container">
<div class="search-section">
<input type="text" id="searchInput" placeholder="搜索 Token...">
</div>
<div class="overview-panel">
<div class="header-actions">
<div class="overview-stats">
<div class="stat-item">
<div class="stat-value" id="totalTokens">0</div>
<div class="stat-label">Token 总数</div>
</div>
<div class="model-remaining-stats">
<div class="model-stat">
<div class="stat-label">grok-2可用次数</div>
<div class="stat-value" id="grok-2-count">0</div>
</div>
<div class="model-stat">
<div class="stat-label">grok-3可用次数</div>
<div class="stat-value" id="grok-3-count">0</div>
</div>
<div class="model-stat">
<div class="stat-label">grok-3-deepsearch可用次数</div>
<div class="stat-value" id="grok-3-deepsearch-count">0</div>
</div>
<div class="model-stat">
<div class="stat-label">grok-3-reasoning可用次数</div>
<div class="stat-value" id="grok-3-reasoning-count">0</div>
</div>
</div>
</div>
<div class="refresh-icon" id="refreshTokens">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8"/>
<path d="M21 3v5h-5"/>
<path d="M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16"/>
<path d="M3 21v-5h5"/>
</svg>
</div>
</div>
</div>
<div class="token-management-section">
<div class="token-input-container">
<h3>添加 SSO Token</h3>
<div class="token-input-section">
<input type="text" id="tokenInput" placeholder="输入新的 SSO Token">
<button id="addTokenBtn">添加 Token</button>
</div>
</div>
<div class="cf-input-container">
<h3>设置 CF Clearance</h3>
<div class="token-input-section">
<input type="text" id="cfInput" placeholder="输入 CF Clearance">
<button id="setCfBtn">设置 CF</button>
</div>
</div>
</div>
<div id="tokenGrid" class="token-grid"></div>
</div>
<div id="notification"></div>
<script>
// Token 模型配置
const modelConfig = {
"grok-2": { RequestFrequency: 30, ExpirationTime: 3600000 },
"grok-3": { RequestFrequency: 20, ExpirationTime: 7200000 },
"grok-3-deepsearch": { RequestFrequency: 10, ExpirationTime: 86400000 },
"grok-3-reasoning": { RequestFrequency: 10, ExpirationTime: 86400000 }
};
let tokenMap = {};
// 根据百分比返回进度条颜色
function getProgressColor(percentage) {
if (percentage > 70) return 'var(--danger-color)';
if (percentage > 30) return 'var(--warning-color)';
return 'var(--success-color)';
}
function calculateModelRemaining() {
const modelRemaining = {};
Object.keys(modelConfig).forEach(modelName => {
const maxRequests = modelConfig[modelName].RequestFrequency;
modelRemaining[modelName] = 0;
Object.values(tokenMap).forEach(tokenData => {
const modelData = tokenData[modelName];
if (modelData.isValid) {
modelRemaining[modelName] += maxRequests - modelData.totalRequestCount;
}
});
});
return modelRemaining;
}
function updateTokenCounters() {
document.getElementById('totalTokens').textContent = Object.keys(tokenMap).length;
const modelRemaining = calculateModelRemaining();
// 更新每个模型的可用次数
const modelIds = ['grok-2', 'grok-3', 'grok-3-deepsearch', 'grok-3-reasoning'];
modelIds.forEach(modelName => {
const countElement = document.getElementById(`${modelName}-count`);
if (countElement) {
countElement.textContent = modelRemaining[modelName] || 0;
}
});
}
// 更新失效 Token 的倒计时,并在时间到达时刷新状态
async function updateExpiredTokenTimers() {
const currentTime = Date.now();
const expiredBadges = document.querySelectorAll('.status-badge.status-expired');
for (const badge of expiredBadges) {
const invalidatedTime = parseInt(badge.getAttribute('data-invalidated-time'), 10);
const expirationTime = parseInt(badge.getAttribute('data-expiration-time'), 10);
const recoveryTime = invalidatedTime + expirationTime;
const remainingTime = recoveryTime - currentTime;
const tooltip = badge.querySelector('.tooltip');
if (tooltip) {
if (remainingTime > 0) {
const minutes = Math.floor(remainingTime / 60000);
const seconds = Math.floor((remainingTime % 60000) / 1000);
tooltip.textContent = `${minutes}分${seconds}秒后恢复`;
} else {
tooltip.textContent = '已可恢复';
await fetchTokenMap();
}
}
}
}
// 渲染 Token 卡片
function renderTokens() {
const tokenGrid = document.getElementById('tokenGrid');
tokenGrid.innerHTML = '';
Object.entries(tokenMap).forEach(([token, tokenData]) => {
const tokenCard = document.createElement('div');
tokenCard.className = 'token-card';
tokenCard.setAttribute('data-token', token);
const tokenHeader = document.createElement('div');
tokenHeader.className = 'token-header';
const tokenTitle = document.createElement('div');
tokenTitle.className = 'token-title';
tokenTitle.textContent = token;
tokenTitle.title = token;
tokenTitle.style.cursor = 'pointer';
tokenTitle.addEventListener('click', () => {
navigator.clipboard.writeText(token).then(() => {
showNotification('Token 已复制');
}).catch(err => {
showNotification('复制失败');
});
});
const deleteBtn = document.createElement('button');
deleteBtn.className = 'delete-btn';
deleteBtn.textContent = '删除';
deleteBtn.addEventListener('click', async () => {
if (confirm(`确认删除 token: ${token}?`)) {
try {
const response = await fetch('/manager/api/delete', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ sso: token })
});
if (response.ok) {
await fetchTokenMap();
showNotification('Token 删除成功');
} else {
showNotification('删除 Token 失败');
}
} catch (error) {
showNotification('删除 Token 出错');
}
}
});
tokenHeader.appendChild(tokenTitle);
tokenHeader.appendChild(deleteBtn);
tokenCard.appendChild(tokenHeader);
Object.entries(modelConfig).forEach(([modelName, config]) => {
const modelRow = document.createElement('div');
modelRow.className = 'model-row';
const modelNameSpan = document.createElement('div');
modelNameSpan.className = 'model-name';
modelNameSpan.textContent = modelName;
const progressContainer = document.createElement('div');
progressContainer.className = 'progress-container';
const progressBar = document.createElement('div');
progressBar.className = 'progress-bar';
const progressBarFill = document.createElement('div');
progressBarFill.className = 'progress-bar-fill';
const modelData = tokenData[modelName];
const requestCount = modelData.totalRequestCount;
const maxRequests = config.RequestFrequency;
const percentage = (requestCount / maxRequests) * 100;
progressBarFill.style.width = `${percentage}%`;
progressBarFill.style.backgroundColor = getProgressColor(percentage);
progressBar.appendChild(progressBarFill);
const progressText = document.createElement('div');
progressText.className = 'progress-text';
progressText.textContent = `${requestCount}/${maxRequests}`;
const statusBadge = document.createElement('div');
statusBadge.className = 'status-badge';
if (!modelData.isValid) {
statusBadge.classList.add('status-expired');
statusBadge.textContent = '失效';
statusBadge.setAttribute('data-invalidated-time', modelData.invalidatedTime);
statusBadge.setAttribute('data-expiration-time', config.ExpirationTime);
const tooltip = document.createElement('div');
tooltip.className = 'tooltip';
statusBadge.appendChild(tooltip);
} else {
statusBadge.classList.add('status-active');
statusBadge.textContent = '活跃';
}
progressContainer.appendChild(progressBar);
progressContainer.appendChild(progressText);
modelRow.appendChild(modelNameSpan);
modelRow.appendChild(progressContainer);
modelRow.appendChild(statusBadge);
tokenCard.appendChild(modelRow);
});
tokenGrid.appendChild(tokenCard);
});
updateTokenCounters();
}
// 获取 Token 数据
async function fetchTokenMap() {
try {
const response = await fetch('/manager/api/get');
if (!response.ok) throw new Error('获取 Token 失败');
tokenMap = await response.json();
renderTokens();
} catch (error) {
showNotification('获取 Token 出错');
}
}
// 添加 Token 事件
document.getElementById('addTokenBtn').addEventListener('click', async () => {
const tokenInput = document.getElementById('tokenInput');
const newToken = tokenInput.value.trim();
if (newToken) {
try {
const response = await fetch('/manager/api/add', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ sso: newToken })
});
if (response.ok) {
tokenInput.value = '';
await fetchTokenMap();
showNotification('Token 添加成功');
} else {
showNotification('添加 Token 失败');
}
} catch (error) {
showNotification('添加 Token 出错');
}
}
});
// 设置 CF Clearance 事件
document.getElementById('setCfBtn').addEventListener('click', async () => {
const cfInput = document.getElementById('cfInput');
const newCf = cfInput.value.trim();
if (newCf) {
try {
const response = await fetch('/manager/api/cf_clearance', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ cf_clearance: newCf })
});
if (response.ok) {
cfInput.value = '';
showNotification('CF Clearance 设置成功');
} else {
showNotification('设置 CF Clearance 失败');
}
} catch (error) {
showNotification('设置 CF Clearance 出错');
}
}
});
// 搜索功能
document.getElementById('searchInput').addEventListener('input', (e) => {
const searchTerm = e.target.value.toLowerCase();
const tokenCards = document.querySelectorAll('.token-card');
tokenCards.forEach(card => {
const token = card.getAttribute('data-token').toLowerCase();
card.style.display = token.includes(searchTerm) ? 'block' : 'none';
});
});
// 刷新 Token 列表事件
document.getElementById('refreshTokens').addEventListener('click', async () => {
await fetchTokenMap();
showNotification('Token 列表已刷新');
});
// 初始化加载 Token 数据
fetchTokenMap();
// 每秒更新失效 Token 的状态
setInterval(updateExpiredTokenTimers, 1000);
// 显示气泡通知
function showNotification(message) {
const notification = document.getElementById('notification');
notification.textContent = message;
notification.style.display = 'block';
setTimeout(() => {
notification.style.display = 'none';
}, 2000);
}
</script>
</body>
</html>
|