Files
cursor-api/static/tokeninfo.html
2024-12-23 15:29:57 +08:00

184 lines
4.2 KiB
HTML

<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Token 信息管理</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 20px auto;
padding: 0 20px;
}
.container {
background: #f5f5f5;
padding: 20px;
border-radius: 8px;
margin-bottom: 20px;
}
.button-group {
display: flex;
gap: 10px;
margin: 10px 0;
}
textarea {
width: 100%;
min-height: 150px;
margin: 10px 0;
font-family: monospace;
resize: vertical;
}
button {
background: #4CAF50;
color: white;
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background: #45a049;
}
button.secondary {
background: #607D8B;
}
button.secondary:hover {
background: #546E7A;
}
.error {
color: red;
margin: 10px 0;
}
.success {
color: green;
margin: 10px 0;
}
#authToken {
width: 100%;
padding: 8px;
margin: 10px 0;
}
</style>
</head>
<body>
<h1>Token 信息管理</h1>
<div class="container">
<h2>认证</h2>
<input type="password" id="authToken" placeholder="输入 AUTH_TOKEN">
</div>
<div class="container">
<h2>Token 配置</h2>
<div class="button-group">
<button onclick="getTokenInfo()">获取当前配置</button>
<button onclick="updateTokenInfo()" class="secondary">保存更改</button>
</div>
<h3>Token 文件内容</h3>
<textarea id="tokens" placeholder="每行一个 token"></textarea>
<h3>Token List 文件内容</h3>
<textarea id="tokenList" placeholder="token,checksum 格式,每行一对"></textarea>
</div>
<div id="message"></div>
<script>
function showMessage(text, isError = false) {
const msg = document.getElementById('message');
msg.className = isError ? 'error' : 'success';
msg.textContent = text;
}
async function getTokenInfo() {
const authToken = document.getElementById('authToken').value;
if (!authToken) {
showMessage('请输入 AUTH_TOKEN', true);
return;
}
try {
const response = await fetch('/get-tokeninfo', {
method: 'POST',
headers: {
'Authorization': `Bearer ${authToken}`
}
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
document.getElementById('tokens').value = data.tokens;
document.getElementById('tokenList').value = data.token_list;
showMessage('配置获取成功');
} catch (error) {
showMessage(`获取失败: ${error.message}`, true);
}
}
async function updateTokenInfo() {
const authToken = document.getElementById('authToken').value;
const tokens = document.getElementById('tokens').value;
const tokenList = document.getElementById('tokenList').value;
if (!authToken) {
showMessage('请输入 AUTH_TOKEN', true);
return;
}
if (!tokens) {
showMessage('Token 文件内容不能为空', true);
return;
}
try {
const response = await fetch('/update-tokeninfo', {
method: 'POST',
headers: {
'Authorization': `Bearer ${authToken}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
tokens: tokens,
token_list: tokenList || undefined
})
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
showMessage(`更新成功: ${data.message}`);
} catch (error) {
showMessage(`更新失败: ${error.message}`, true);
}
}
// 快捷键支持
document.addEventListener('keydown', function (e) {
if (e.ctrlKey && e.key === 's') {
e.preventDefault();
updateTokenInfo();
}
});
</script>
</body>
</html>