mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-23 00:53:33 +00:00
refactor: 优化API Key状态更新和日志记录格式
This commit is contained in:
@@ -1124,9 +1124,7 @@ class DroidAccountService {
|
|||||||
updatedHashes.add(hash)
|
updatedHashes.add(hash)
|
||||||
|
|
||||||
// 查找现有条目
|
// 查找现有条目
|
||||||
const existingIndex = mergedApiKeys.findIndex(
|
const existingIndex = mergedApiKeys.findIndex((entry) => entry && entry.hash === hash)
|
||||||
(entry) => entry && entry.hash === hash
|
|
||||||
)
|
|
||||||
|
|
||||||
if (existingIndex !== -1) {
|
if (existingIndex !== -1) {
|
||||||
// 更新现有条目的状态信息
|
// 更新现有条目的状态信息
|
||||||
@@ -1134,9 +1132,18 @@ class DroidAccountService {
|
|||||||
mergedApiKeys[existingIndex] = {
|
mergedApiKeys[existingIndex] = {
|
||||||
...existingEntry,
|
...existingEntry,
|
||||||
status: updateItem.status || existingEntry.status || 'active',
|
status: updateItem.status || existingEntry.status || 'active',
|
||||||
errorMessage: updateItem.errorMessage !== undefined ? updateItem.errorMessage : existingEntry.errorMessage || '',
|
errorMessage:
|
||||||
lastUsedAt: updateItem.lastUsedAt !== undefined ? updateItem.lastUsedAt : existingEntry.lastUsedAt || '',
|
updateItem.errorMessage !== undefined
|
||||||
usageCount: updateItem.usageCount !== undefined ? String(updateItem.usageCount) : existingEntry.usageCount || '0'
|
? updateItem.errorMessage
|
||||||
|
: existingEntry.errorMessage || '',
|
||||||
|
lastUsedAt:
|
||||||
|
updateItem.lastUsedAt !== undefined
|
||||||
|
? updateItem.lastUsedAt
|
||||||
|
: existingEntry.lastUsedAt || '',
|
||||||
|
usageCount:
|
||||||
|
updateItem.usageCount !== undefined
|
||||||
|
? String(updateItem.usageCount)
|
||||||
|
: existingEntry.usageCount || '0'
|
||||||
}
|
}
|
||||||
apiKeysUpdated = true
|
apiKeysUpdated = true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1182,15 +1182,13 @@ class DroidRelayService {
|
|||||||
// 检查是否还有可用的API Key
|
// 检查是否还有可用的API Key
|
||||||
try {
|
try {
|
||||||
const availableEntries = await droidAccountService.getDecryptedApiKeyEntries(accountId)
|
const availableEntries = await droidAccountService.getDecryptedApiKeyEntries(accountId)
|
||||||
const activeEntries = availableEntries.filter(entry => entry.status !== 'error')
|
const activeEntries = availableEntries.filter((entry) => entry.status !== 'error')
|
||||||
|
|
||||||
if (activeEntries.length === 0) {
|
if (activeEntries.length === 0) {
|
||||||
await this._stopDroidAccountScheduling(accountId, statusCode, '所有API Key均已异常')
|
await this._stopDroidAccountScheduling(accountId, statusCode, '所有API Key均已异常')
|
||||||
await this._clearAccountStickyMapping(normalizedEndpoint, sessionHash, clientApiKeyId)
|
await this._clearAccountStickyMapping(normalizedEndpoint, sessionHash, clientApiKeyId)
|
||||||
} else {
|
} else {
|
||||||
logger.info(
|
logger.info(`ℹ️ Droid 账号 ${accountId} 仍有 ${activeEntries.length} 个可用 API Key`)
|
||||||
`ℹ️ Droid 账号 ${accountId} 仍有 ${activeEntries.length} 个可用 API Key`
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`❌ 检查可用API Key失败(Account: ${accountId}):`, error)
|
logger.error(`❌ 检查可用API Key失败(Account: ${accountId}):`, error)
|
||||||
|
|||||||
Reference in New Issue
Block a user