mirror of
https://github.com/snailyp/gemini-balance.git
synced 2026-05-06 20:32:47 +08:00
fix(verify-keys): 修复无效秘钥的批量验证
This commit is contained in:
@@ -475,111 +475,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
}
|
||||
|
||||
|
||||
window.showVerifyModal = function(type, event) {
|
||||
// 阻止事件冒泡(如果从按钮点击触发)
|
||||
if (event) {
|
||||
event.stopPropagation();
|
||||
}
|
||||
|
||||
const modalElement = document.getElementById('verifyModal');
|
||||
const titleElement = document.getElementById('verifyModalTitle');
|
||||
const messageElement = document.getElementById('verifyModalMessage');
|
||||
const confirmButton = document.getElementById('confirmVerifyBtn');
|
||||
|
||||
// 获取当前筛选后可见的、且包含 data-fail-count 属性的密钥数量
|
||||
// 注意:对于验证,我们可能想验证所有筛选出的密钥,无论其 data-fail-count 如何,
|
||||
// 但为了与重置保持一致,并且通常只验证有效/无效列表中的项,我们保留 data-fail-count 检查。
|
||||
// 如果要验证所有可见项(包括没有 data-fail-count 的),可以移除 [data-fail-count] 选择器。
|
||||
const visibleKeyItems = document.querySelectorAll(`#${type}Keys li[data-fail-count]:not([style*="display: none"])`);
|
||||
const count = visibleKeyItems.length;
|
||||
|
||||
// 设置标题和消息
|
||||
titleElement.textContent = '批量验证密钥';
|
||||
if (count > 0) {
|
||||
messageElement.textContent = `确定要批量验证筛选出的 ${count} 个${type === 'valid' ? '有效' : '无效'}密钥吗?此操作可能需要一些时间。`;
|
||||
confirmButton.disabled = false; // 确保按钮可用
|
||||
} else {
|
||||
messageElement.textContent = `当前没有筛选出可验证的${type === 'valid' ? '有效' : '无效'}密钥。`;
|
||||
confirmButton.disabled = true; // 没有可验证的密钥时禁用确认按钮
|
||||
}
|
||||
|
||||
// 设置确认按钮事件
|
||||
confirmButton.onclick = () => executeVerifyAll(type);
|
||||
|
||||
// 显示模态框
|
||||
modalElement.classList.remove('hidden');
|
||||
}
|
||||
|
||||
window.closeVerifyModal = function() {
|
||||
document.getElementById('verifyModal').classList.add('hidden');
|
||||
}
|
||||
|
||||
window.executeVerifyAll = async function(type) {
|
||||
try {
|
||||
// 关闭确认模态框
|
||||
closeVerifyModal();
|
||||
|
||||
// 找到对应的验证按钮以显示加载状态 (需要给按钮添加 data-verify-type 属性)
|
||||
// 或者,我们可以暂时禁用所有按钮或显示一个全局加载指示器
|
||||
// 这里我们暂时只记录日志,实际UI反馈可以后续增强
|
||||
console.log(`Starting bulk verification for ${type} keys...`);
|
||||
|
||||
// 获取筛选后可见的密钥
|
||||
const visibleKeyItems = document.querySelectorAll(`#${type}Keys li[data-fail-count]:not([style*="display: none"]) .key-text`);
|
||||
const keysToVerify = Array.from(visibleKeyItems).map(span => span.dataset.fullKey);
|
||||
|
||||
if (keysToVerify.length === 0) {
|
||||
showNotification(`没有需要验证的筛选后${type === 'valid' ? '有效' : '无效'}密钥`, 'warning');
|
||||
return;
|
||||
}
|
||||
|
||||
// 显示一个通用的加载提示
|
||||
showNotification('开始批量验证,请稍候...', 'info');
|
||||
|
||||
// 调用新的后端 API 来验证选定的密钥
|
||||
const response = await fetch(`/gemini/v1beta/verify-selected-keys`, { // 假设的新 API 端点
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ keys: keysToVerify }) // 只发送密钥列表
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
let errorMsg = `服务器返回错误: ${response.status}`;
|
||||
try {
|
||||
const errorData = await response.json();
|
||||
errorMsg = errorData.message || errorMsg;
|
||||
} catch (e) { /*忽略解析错误*/ }
|
||||
throw new Error(errorMsg);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
// 根据验证结果显示模态框
|
||||
if (data.success) {
|
||||
// 可以在这里构建更详细的消息,例如显示多少有效多少无效
|
||||
const message = `批量验证完成。有效: ${data.valid_count}, 无效: ${data.invalid_count}。页面即将刷新。`;
|
||||
// 验证成功后通常需要刷新页面以更新状态
|
||||
showResultModal(true, message, true); // autoReload = true
|
||||
} else {
|
||||
const errorMsg = data.message || '批量验证失败';
|
||||
// 失败后不自动刷新
|
||||
showResultModal(false, '批量验证失败: ' + errorMsg, false);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('批量验证处理失败:', error);
|
||||
// 失败后不自动刷新
|
||||
showResultModal(false, '批量验证处理失败: ' + error.message, false);
|
||||
} finally {
|
||||
// 可以在这里移除加载指示器
|
||||
console.log("Bulk verification process finished.");
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
requestAnimationFrame(updateCounter);
|
||||
}
|
||||
});
|
||||
@@ -633,13 +529,19 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
const messageElement = document.getElementById('verifyModalMessage');
|
||||
const confirmButton = document.getElementById('confirmVerifyBtn');
|
||||
|
||||
// 获取当前筛选后可见的、且包含 data-fail-count 属性的密钥数量
|
||||
// 注意:对于验证,我们可能想验证所有筛选出的密钥,无论其 data-fail-count 如何,
|
||||
// 但为了与重置保持一致,并且通常只验证有效/无效列表中的项,我们保留 data-fail-count 检查。
|
||||
// 如果要验证所有可见项(包括没有 data-fail-count 的),可以移除 [data-fail-count] 选择器。
|
||||
const visibleKeyItems = document.querySelectorAll(`#${type}Keys li[data-fail-count]:not([style*="display: none"])`);
|
||||
// 根据密钥类型选择合适的选择器来确定可验证的密钥
|
||||
let keySelector;
|
||||
if (type === 'valid') {
|
||||
// 对于有效密钥,可以根据需要决定是否只验证有失败记录的,或所有可见的
|
||||
// 暂时保留 data-fail-count,如果需要验证所有可见有效密钥,则移除
|
||||
keySelector = `#${type}Keys li[data-fail-count]:not([style*="display: none"])`;
|
||||
} else { // type === 'invalid'
|
||||
// 对于无效密钥,应该验证所有可见的无效密钥
|
||||
keySelector = `#${type}Keys li:not([style*="display: none"])`;
|
||||
}
|
||||
const visibleKeyItems = document.querySelectorAll(keySelector);
|
||||
const count = visibleKeyItems.length;
|
||||
|
||||
|
||||
// 设置标题和消息
|
||||
titleElement.textContent = '批量验证密钥';
|
||||
if (count > 0) {
|
||||
@@ -671,10 +573,17 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
// 这里我们暂时只记录日志,实际UI反馈可以后续增强
|
||||
console.log(`Starting bulk verification for ${type} keys...`);
|
||||
|
||||
// 获取筛选后可见的密钥
|
||||
const visibleKeyItems = document.querySelectorAll(`#${type}Keys li[data-fail-count]:not([style*="display: none"]) .key-text`);
|
||||
// 根据密钥类型选择合适的选择器来获取待验证的密钥
|
||||
let keySelector;
|
||||
if (type === 'valid') {
|
||||
// 同上,根据需求决定是否保留 data-fail-count
|
||||
keySelector = `#${type}Keys li[data-fail-count]:not([style*="display: none"]) .key-text`;
|
||||
} else { // type === 'invalid'
|
||||
keySelector = `#${type}Keys li:not([style*="display: none"]) .key-text`;
|
||||
}
|
||||
const visibleKeyItems = document.querySelectorAll(keySelector);
|
||||
const keysToVerify = Array.from(visibleKeyItems).map(span => span.dataset.fullKey);
|
||||
|
||||
|
||||
if (keysToVerify.length === 0) {
|
||||
showNotification(`没有需要验证的筛选后${type === 'valid' ? '有效' : '无效'}密钥`, 'warning');
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user