mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-22 16:43:35 +00:00
feat: 完善Gemini-Api账户相关的数据统计
This commit is contained in:
@@ -5842,16 +5842,32 @@ router.get('/account-usage-trend', authenticateAdmin, async (req, res) => {
|
||||
})
|
||||
]
|
||||
} else if (group === 'gemini') {
|
||||
const geminiAccounts = await geminiAccountService.getAllAccounts()
|
||||
accounts = geminiAccounts.map((account) => {
|
||||
const id = String(account.id || '')
|
||||
const shortId = id ? id.slice(0, 8) : '未知'
|
||||
return {
|
||||
id,
|
||||
name: account.name || account.email || `Gemini账号 ${shortId}`,
|
||||
platform: 'gemini'
|
||||
}
|
||||
})
|
||||
const geminiApiAccountService = require('../services/geminiApiAccountService')
|
||||
const [geminiAccounts, geminiApiAccounts] = await Promise.all([
|
||||
geminiAccountService.getAllAccounts(),
|
||||
geminiApiAccountService.getAllAccounts(true)
|
||||
])
|
||||
|
||||
accounts = [
|
||||
...geminiAccounts.map((account) => {
|
||||
const id = String(account.id || '')
|
||||
const shortId = id ? id.slice(0, 8) : '未知'
|
||||
return {
|
||||
id,
|
||||
name: account.name || account.email || `Gemini账号 ${shortId}`,
|
||||
platform: 'gemini'
|
||||
}
|
||||
}),
|
||||
...geminiApiAccounts.map((account) => {
|
||||
const id = String(account.id || '')
|
||||
const shortId = id ? id.slice(0, 8) : '未知'
|
||||
return {
|
||||
id,
|
||||
name: account.name || `Gemini-API账号 ${shortId}`,
|
||||
platform: 'gemini-api'
|
||||
}
|
||||
})
|
||||
]
|
||||
} else if (group === 'droid') {
|
||||
const droidAccounts = await droidAccountService.getAllAccounts()
|
||||
accounts = droidAccounts.map((account) => {
|
||||
|
||||
@@ -11,6 +11,7 @@ const ACCOUNT_TYPE_CONFIG = {
|
||||
'openai-responses': { prefix: 'openai_responses_account:' },
|
||||
'azure-openai': { prefix: 'azure_openai:account:' },
|
||||
gemini: { prefix: 'gemini_account:' },
|
||||
'gemini-api': { prefix: 'gemini_api_account:' },
|
||||
droid: { prefix: 'droid:account:' }
|
||||
}
|
||||
|
||||
@@ -21,6 +22,7 @@ const ACCOUNT_TYPE_PRIORITY = [
|
||||
'claude',
|
||||
'claude-console',
|
||||
'gemini',
|
||||
'gemini-api',
|
||||
'droid'
|
||||
]
|
||||
|
||||
@@ -31,6 +33,7 @@ const ACCOUNT_CATEGORY_MAP = {
|
||||
'openai-responses': 'openai',
|
||||
'azure-openai': 'openai',
|
||||
gemini: 'gemini',
|
||||
'gemini-api': 'gemini',
|
||||
droid: 'droid'
|
||||
}
|
||||
|
||||
@@ -48,6 +51,9 @@ function normalizeAccountTypeKey(type) {
|
||||
if (lower === 'azure_openai' || lower === 'azureopenai' || lower === 'azure-openai') {
|
||||
return 'azure-openai'
|
||||
}
|
||||
if (lower === 'gemini_api' || lower === 'gemini-api') {
|
||||
return 'gemini-api'
|
||||
}
|
||||
return lower
|
||||
}
|
||||
|
||||
@@ -58,6 +64,9 @@ function sanitizeAccountIdForType(accountId, accountType) {
|
||||
if (accountType === 'openai-responses') {
|
||||
return accountId.replace(/^responses:/, '')
|
||||
}
|
||||
if (accountType === 'gemini-api') {
|
||||
return accountId.replace(/^api:/, '')
|
||||
}
|
||||
return accountId
|
||||
}
|
||||
|
||||
@@ -1322,6 +1331,9 @@ class ApiKeyService {
|
||||
if (typeof rawAccountId === 'string' && rawAccountId.startsWith('responses:')) {
|
||||
candidateIds.add(rawAccountId.replace(/^responses:/, ''))
|
||||
}
|
||||
if (typeof rawAccountId === 'string' && rawAccountId.startsWith('api:')) {
|
||||
candidateIds.add(rawAccountId.replace(/^api:/, ''))
|
||||
}
|
||||
}
|
||||
|
||||
if (candidateIds.size === 0) {
|
||||
@@ -1346,6 +1358,7 @@ class ApiKeyService {
|
||||
pushType('azure-openai')
|
||||
} else if (lowerModel.includes('gemini')) {
|
||||
pushType('gemini')
|
||||
pushType('gemini-api')
|
||||
} else if (lowerModel.includes('claude') || lowerModel.includes('anthropic')) {
|
||||
pushType('claude')
|
||||
pushType('claude-console')
|
||||
|
||||
@@ -3814,7 +3814,7 @@ const normalizeFrontendAccountCategory = (type) => {
|
||||
) {
|
||||
return 'openai'
|
||||
}
|
||||
if (lower === 'gemini') {
|
||||
if (lower === 'gemini' || lower === 'gemini-api' || lower === 'gemini_api') {
|
||||
return 'gemini'
|
||||
}
|
||||
if (lower === 'droid') {
|
||||
@@ -3843,8 +3843,8 @@ const isLikelyDeletedUsage = (info) => {
|
||||
|
||||
const looksLikeUuid = UUID_PATTERN.test(rawId)
|
||||
const nameMissingOrSame = !accountName || accountName === rawId
|
||||
const typeUnknown =
|
||||
!accountType || accountType === 'unknown' || ACCOUNT_TYPE_LABELS[accountType] === undefined
|
||||
const normalizedType = normalizeFrontendAccountCategory(accountType)
|
||||
const typeUnknown = !accountType || accountType === 'unknown' || normalizedType === 'other'
|
||||
|
||||
return looksLikeUuid && nameMissingOrSame && typeUnknown
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user