File size: 22,561 Bytes
6e70660 |
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 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 |
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Augment2Api</title>
<style>
:root {
--primary-color: #4361ee;
--secondary-color: #3f37c9;
--success-color: #4caf50;
--error-color: #f44336;
--bg-color: #f8f9fa;
--card-bg: #ffffff;
--text-color: #333333;
--border-color: #e0e0e0;
--shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
--radius: 8px;
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: 'PingFang SC', 'Microsoft YaHei', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
background-color: var(--bg-color);
color: var(--text-color);
line-height: 1.6;
padding: 20px;
min-height: 100vh;
display: flex;
flex-direction: column;
}
.container {
max-width: 1200px;
margin: 0 auto;
flex: 1;
display: flex;
flex-direction: column;
}
header {
text-align: center;
margin-bottom: 30px;
padding-bottom: 15px;
border-bottom: 1px solid var(--border-color);
}
h1 {
font-size: 28px;
font-weight: 600;
color: black;
}
h2 {
font-size: 20px;
font-weight: 500;
margin-bottom: 15px;
color: var(--secondary-color);
}
.dashboard {
display: flex;
flex-direction: row;
gap: 20px;
align-items: stretch;
min-height: 500px;
}
@media (max-width: 768px) {
.dashboard {
flex-direction: column;
}
}
.panel {
background: var(--card-bg);
border-radius: var(--radius);
box-shadow: var(--shadow);
padding: 25px;
display: flex;
flex-direction: column;
}
.panel-left {
width: 50%;
max-width: 580px;
flex: 1;
}
.panel-right {
width: 50%;
max-width: 580px;
flex: 1;
position: sticky;
top: 20px;
}
@media (max-width: 768px) {
.panel-left, .panel-right {
width: 100%;
max-width: none;
}
}
.panel-title {
display: flex;
align-items: center;
margin-bottom: 20px;
}
.panel-title i {
margin-right: 10px;
font-size: 20px;
color: var(--primary-color);
}
.panel-title h2 {
margin-bottom: 0;
}
.token-display {
background: var(--bg-color);
padding: 15px;
border-radius: var(--radius);
word-break: break-all;
margin: 15px 0;
border: 1px solid var(--border-color);
font-family: monospace;
font-size: 14px;
position: relative;
}
.token-label {
font-weight: 500;
margin-bottom: 5px;
color: #666;
}
button {
background: var(--primary-color);
color: white;
border: none;
padding: 10px 15px;
border-radius: var(--radius);
cursor: pointer;
font-size: 14px;
margin-top: 10px;
transition: background 0.3s;
display: inline-flex;
align-items: center;
justify-content: center;
}
button:hover {
background: var(--secondary-color);
}
button i {
margin-right: 8px;
}
input, textarea {
width: 100%;
padding: 12px;
margin: 10px 0;
border: 1px solid var(--border-color);
border-radius: var(--radius);
font-size: 14px;
transition: border 0.3s;
}
input:focus, textarea:focus {
outline: none;
border-color: var(--primary-color);
}
textarea {
height: 120px;
resize: vertical;
}
.error {
color: var(--error-color);
margin: 10px 0;
padding: 10px;
background-color: rgba(244, 67, 54, 0.1);
border-radius: var(--radius);
display: none;
}
.success {
color: var(--success-color);
margin: 10px 0;
padding: 10px;
background-color: rgba(76, 175, 80, 0.1);
border-radius: var(--radius);
display: none;
}
.step {
margin-bottom: 20px;
padding-bottom: 20px;
border-bottom: 1px dashed var(--border-color);
}
.step:last-child {
border-bottom: none;
}
.step-number {
display: inline-block;
width: 24px;
height: 24px;
background-color: var(--primary-color);
color: white;
border-radius: 50%;
text-align: center;
line-height: 24px;
margin-right: 10px;
font-size: 14px;
}
/* 添加一些图标 */
.icon {
display: inline-block;
width: 1em;
height: 1em;
stroke-width: 0;
stroke: currentColor;
fill: currentColor;
vertical-align: middle;
}
/* 添加Token列表样式 */
.token-list {
display: flex;
flex-direction: column;
gap: 15px;
margin-bottom: 15px;
max-height: 500px;
overflow-y: auto;
padding-right: 10px;
}
.token-item {
background: var(--bg-color);
border-radius: var(--radius);
border: 1px solid var(--border-color);
overflow: hidden;
transition: all 0.3s ease;
}
.current-token {
border: 2px solid var(--primary-color);
}
.token-header {
display: flex;
padding: 12px 15px;
cursor: pointer;
align-items: center;
background: #f0f2f5;
}
.token-number {
background: var(--primary-color);
color: white;
padding: 6px 10px;
display: flex;
align-items: center;
justify-content: center;
font-weight: bold;
min-width: 30px;
border-radius: 4px;
margin-right: 12px;
}
.token-summary {
flex: 1;
font-weight: 500;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.token-toggle {
margin-left: 10px;
transition: transform 0.3s;
}
.token-toggle.open {
transform: rotate(180deg);
}
.token-details {
padding: 0;
max-height: 0;
overflow: hidden;
transition: all 0.3s ease;
}
.token-details.open {
padding: 12px;
max-height: none;
overflow: visible;
}
.token-details .token-label {
font-size: 13px;
margin-bottom: 3px;
}
.token-details .token-display {
font-size: 13px;
padding: 10px;
margin: 5px 0 10px 0;
}
.token-actions {
display: flex;
justify-content: flex-end;
margin-top: 8px;
}
.token-actions button {
margin-left: 10px;
padding: 6px 12px;
font-size: 13px;
}
.no-tokens {
padding: 20px;
text-align: center;
background: var(--bg-color);
border-radius: var(--radius);
color: #666;
margin-bottom: 15px;
}
/* 添加加载动画样式 */
.loading {
position: relative;
pointer-events: none;
}
.loading:after {
content: '';
display: inline-block;
width: 1em;
height: 1em;
border: 2px solid rgba(255, 255, 255, 0.3);
border-radius: 50%;
border-top-color: white;
animation: spin 0.8s linear infinite;
margin-left: 8px;
vertical-align: middle;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
.btn-text {
display: inline-block;
}
.loading .btn-icon {
display: none;
}
/* 添加页脚样式 */
footer {
text-align: center;
margin-top: 30px;
padding: 15px 0;
color: #666;
font-size: 14px;
border-top: 1px solid var(--border-color);
margin-top: auto;
}
footer a {
color: var(--primary-color);
text-decoration: none;
transition: color 0.3s;
}
footer a:hover {
color: var(--secondary-color);
text-decoration: underline;
}
</style>
<!-- 添加图标 -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
</head>
<body>
<div class="container">
<header>
<h1>Augment面板</h1>
</header>
<div class="dashboard">
<!-- 左侧面板:查看当前Token -->
<div class="panel panel-left">
<div class="panel-title">
<i class="bi bi-key-fill"></i>
<h2>当前Token列表</h2>
</div>
<div id="token-list">加载中...</div>
<button id="refresh-token"><i class="bi bi-arrow-clockwise btn-icon"></i> <span class="btn-text">刷新</span></button>
</div>
<!-- 右侧面板:授权获取Token -->
<div class="panel panel-right">
<div class="panel-title">
<i class="bi bi-shield-lock-fill"></i>
<h2>授权获取Token</h2>
</div>
<div class="auth-steps">
<div class="step">
<h3><span class="step-number">1</span> 获取授权地址</h3>
<p>点击下方按钮获取授权地址,然后在浏览器中打开该地址进行授权。</p>
<button id="get-auth-url"><i class="bi bi-link-45deg" class="btn-icon"></i> <span class="btn-text">获取授权地址</span></button>
<div id="auth-url" class="token-display" style="display: none;"></div>
</div>
<div class="step">
<h3><span class="step-number">2</span> 提交授权响应</h3>
<p>完成授权后,将获得的授权响应粘贴到下面的文本框中:</p>
<textarea id="auth-response" placeholder='{"code":"_000baec407c57c4bf9xxxxxxxxxxxxxx","state":"0uXxxxxxxxx","tenant_url":"https://d20.api.augmentcode.com/"}'></textarea>
<div id="validation-message" class="error"></div>
<button id="submit-auth"><i class="bi bi-check2-circle" class="btn-icon"></i> <span class="btn-text">获取Token</span></button>
<div id="submit-result" class="success"></div>
</div>
</div>
</div>
</div>
<!-- 添加页脚 -->
<footer>
Designed by <a href="https://linux.do/u/bifang/summary" target="_blank">彼方</a>
</footer>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
// 获取当前Token列表
function fetchCurrentToken() {
fetch('/api/tokens')
.then(response => response.json())
.then(data => {
if (data.status === 'success') {
const tokenListElement = document.getElementById('token-list');
if (data.tokens.length === 0) {
tokenListElement.innerHTML = '<div class="no-tokens">暂无可用Token,请点击右侧面板获取</div>';
return;
}
// 创建token列表容器
tokenListElement.innerHTML = '<div class="token-list"></div>';
const listContainer = tokenListElement.querySelector('.token-list');
// 添加每个token项
data.tokens.forEach((tokenInfo, index) => {
// 截断token以便显示
const shortToken = tokenInfo.token.length > 15
? tokenInfo.token.substring(0, 15) + '...'
: tokenInfo.token;
const tokenItem = document.createElement('div');
tokenItem.className = 'token-item';
tokenItem.innerHTML = `
<div class="token-header">
<div class="token-number">${index + 1}</div>
<div class="token-summary">${shortToken}</div>
<div class="token-toggle"><i class="bi bi-chevron-down"></i></div>
</div>
<div class="token-details">
<div class="token-label">Token:</div>
<div class="token-display">${tokenInfo.token}</div>
<div class="token-label">租户URL:</div>
<div class="token-display">${tokenInfo.tenant_url}</div>
<div class="token-actions">
<button class="delete-token" data-token="${tokenInfo.token}">
<i class="bi bi-trash"></i> 删除
</button>
</div>
</div>
`;
listContainer.appendChild(tokenItem);
// 添加点击事件
const header = tokenItem.querySelector('.token-header');
const details = tokenItem.querySelector('.token-details');
const toggle = tokenItem.querySelector('.token-toggle');
header.addEventListener('click', function() {
details.classList.toggle('open');
toggle.classList.toggle('open');
});
});
} else {
showError('获取Token列表失败: ' + (data.error || '未知错误'));
}
})
.catch(error => {
document.getElementById('token-list').innerHTML =
'<div class="error" style="display:block;">请求失败: ' + error.message + '</div>';
});
return Promise.resolve(); // 确保可以使用.finally()
}
// 显示错误信息的辅助函数
function showError(message) {
const tokenListElement = document.getElementById('token-list');
tokenListElement.innerHTML = `<div class="error" style="display:block;">${message}</div>`;
}
// 获取授权地址
document.getElementById('get-auth-url').addEventListener('click', function() {
const button = this;
button.classList.add('loading');
fetch('/auth')
.then(response => response.json())
.then(data => {
const authUrlElement = document.getElementById('auth-url');
authUrlElement.textContent = data.authorize_url;
authUrlElement.style.display = 'block';
})
.catch(error => {
alert('获取授权地址失败: ' + error.message);
})
.finally(() => {
button.classList.remove('loading');
});
});
// 验证授权响应格式
function validateAuthResponse(response) {
try {
const data = JSON.parse(response);
if (!data.code || !data.state || !data.tenant_url) {
return { valid: false, message: '缺少必要字段: code, state 或 tenant_url' };
}
return { valid: true };
} catch (e) {
return { valid: false, message: 'JSON格式无效: ' + e.message };
}
}
// 提交授权响应
document.getElementById('submit-auth').addEventListener('click', function() {
const button = this;
const authResponse = document.getElementById('auth-response').value.trim();
const validationMessage = document.getElementById('validation-message');
// 检查是否为空
if (!authResponse) {
validationMessage.textContent = '请输入授权响应';
validationMessage.style.display = 'block';
return;
}
const validationResult = validateAuthResponse(authResponse);
if (!validationResult.valid) {
validationMessage.textContent = validationResult.message;
validationMessage.style.display = 'block';
return;
}
validationMessage.style.display = 'none';
button.classList.add('loading');
fetch('/callback', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: authResponse
})
.then(response => response.json())
.then(data => {
const submitResult = document.getElementById('submit-result');
if (data.status === 'success') {
submitResult.textContent = 'Token获取成功!';
submitResult.className = 'success';
fetchCurrentToken(); // 刷新当前Token显示
} else {
submitResult.textContent = '获取失败: ' + (data.error || '未知错误');
submitResult.className = 'error';
}
submitResult.style.display = 'block';
})
.catch(error => {
const submitResult = document.getElementById('submit-result');
submitResult.textContent = '请求失败: ' + error.message;
submitResult.className = 'error';
submitResult.style.display = 'block';
})
.finally(() => {
button.classList.remove('loading');
});
});
// 刷新Token
document.getElementById('refresh-token').addEventListener('click', function() {
const button = this;
button.classList.add('loading');
fetchCurrentToken()
.finally(() => {
button.classList.remove('loading');
});
});
// 绑定删除按钮事件
document.addEventListener('click', function(e) {
if (e.target.closest('.delete-token')) {
const button = e.target.closest('.delete-token');
const token = button.dataset.token;
if (confirm('确定要删除此Token吗?')) {
fetch(`/api/token/${token}`, {
method: 'DELETE'
})
.then(response => response.json())
.then(data => {
if (data.status === 'success') {
fetchCurrentToken(); // 刷新列表
} else {
alert('删除失败: ' + (data.error || '未知错误'));
}
})
.catch(error => {
alert('请求失败: ' + error.message);
});
}
}
});
// 初始加载
fetchCurrentToken();
});
</script>
</body>
</html> |