Merge pull request #561 from AAEE86/new

feat: 添加Droid账户API Key管理功能
This commit is contained in:
Wesley Liddick
2025-10-14 14:34:07 +08:00
committed by GitHub
6 changed files with 753 additions and 41 deletions

View File

@@ -3108,6 +3108,25 @@ const getDroidApiKeyCount = (account) => {
return 0
}
// 优先使用 apiKeys 数组来计算正常状态的 API Keys
if (Array.isArray(account.apiKeys)) {
// 只计算状态不是 'error' 的 API Keys
return account.apiKeys.filter((apiKey) => apiKey.status !== 'error').length
}
// 如果是字符串格式的 apiKeys尝试解析
if (typeof account.apiKeys === 'string' && account.apiKeys.trim()) {
try {
const parsed = JSON.parse(account.apiKeys)
if (Array.isArray(parsed)) {
// 只计算状态不是 'error' 的 API Keys
return parsed.filter((apiKey) => apiKey.status !== 'error').length
}
} catch (error) {
// 忽略解析错误,继续使用其他字段
}
}
const candidates = [
account.apiKeyCount,
account.api_key_count,
@@ -3122,21 +3141,6 @@ const getDroidApiKeyCount = (account) => {
}
}
if (Array.isArray(account.apiKeys)) {
return account.apiKeys.length
}
if (typeof account.apiKeys === 'string' && account.apiKeys.trim()) {
try {
const parsed = JSON.parse(account.apiKeys)
if (Array.isArray(parsed)) {
return parsed.length
}
} catch (error) {
// 忽略解析错误,维持默认值
}
}
return 0
}