From 945e0ac198ad2f0d747702d8eea8d04b5ec03059 Mon Sep 17 00:00:00 2001 From: sczheng189 <724100151@qq.com> Date: Tue, 2 Sep 2025 20:21:24 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=B2=BE=E7=AE=80Azure=20OpenAI?= =?UTF-8?q?=E5=A4=9A=E5=88=86=E7=BB=84=E5=8A=9F=E8=83=BD=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除不必要的分组清理逻辑 - 简化组成员端点实现,使用简单的members.push() - 移除OpenAI账户路由中的groupInfos添加 - 保持最小化修改原则,只保留必要的功能实现 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/routes/admin.js | 60 ++++------------------------ src/services/geminiAccountService.js | 4 -- src/services/openaiAccountService.js | 4 -- 3 files changed, 8 insertions(+), 60 deletions(-) diff --git a/src/routes/admin.js b/src/routes/admin.js index d38d3c4d..eb8c9be6 100644 --- a/src/routes/admin.js +++ b/src/routes/admin.js @@ -1183,34 +1183,7 @@ router.get('/account-groups/:groupId/members', authenticateAdmin, async (req, re } if (account) { - try { - // 添加使用统计信息 - const usageStats = await redis.getAccountUsageStats(account.id) - const groupInfos = await accountGroupService.getAccountGroups(account.id) - - members.push({ - ...account, - groupInfos, - usage: { - daily: usageStats.daily, - total: usageStats.total, - averages: usageStats.averages - } - }) - } catch (statsError) { - logger.warn(`⚠️ Failed to get usage stats for account ${account.id}:`, statsError.message) - // 如果获取统计失败,返回空统计 - const groupInfos = await accountGroupService.getAccountGroups(account.id).catch(() => []) - members.push({ - ...account, - groupInfos, - usage: { - daily: { tokens: 0, requests: 0 }, - total: { tokens: 0, requests: 0 }, - averages: { tokensPerRequest: 0 } - } - }) - } + members.push(account) } } @@ -5173,15 +5146,13 @@ router.get('/openai-accounts', authenticateAdmin, async (req, res) => { } } - // 为每个账户添加使用统计信息和分组信息 + // 为每个账户添加使用统计信息 const accountsWithStats = await Promise.all( accounts.map(async (account) => { try { const usageStats = await redis.getAccountUsageStats(account.id) - const groupInfos = await accountGroupService.getAccountGroups(account.id) return { ...account, - groupInfos, usage: { daily: usageStats.daily, total: usageStats.total, @@ -5190,27 +5161,12 @@ router.get('/openai-accounts', authenticateAdmin, async (req, res) => { } } catch (error) { logger.debug(`Failed to get usage stats for OpenAI account ${account.id}:`, error) - try { - const groupInfos = await accountGroupService.getAccountGroups(account.id) - return { - ...account, - groupInfos, - usage: { - daily: { requests: 0, tokens: 0, allTokens: 0 }, - total: { requests: 0, tokens: 0, allTokens: 0 }, - averages: { rpm: 0, tpm: 0 } - } - } - } catch (groupError) { - logger.debug(`Failed to get group info for account ${account.id}:`, groupError) - return { - ...account, - groupInfos: [], - usage: { - daily: { requests: 0, tokens: 0, allTokens: 0 }, - total: { requests: 0, tokens: 0, allTokens: 0 }, - averages: { rpm: 0, tpm: 0 } - } + return { + ...account, + usage: { + daily: { requests: 0, tokens: 0, allTokens: 0 }, + total: { requests: 0, tokens: 0, allTokens: 0 }, + monthly: { requests: 0, tokens: 0, allTokens: 0 } } } } diff --git a/src/services/geminiAccountService.js b/src/services/geminiAccountService.js index 137ad7a5..78e1d5a1 100644 --- a/src/services/geminiAccountService.js +++ b/src/services/geminiAccountService.js @@ -585,10 +585,6 @@ async function deleteAccount(accountId) { throw new Error('Account not found') } - // 首先从所有分组中移除此账户 - const accountGroupService = require('./accountGroupService') - await accountGroupService.removeAccountFromAllGroups(accountId) - // 从 Redis 删除 const client = redisClient.getClientSafe() await client.del(`${GEMINI_ACCOUNT_KEY_PREFIX}${accountId}`) diff --git a/src/services/openaiAccountService.js b/src/services/openaiAccountService.js index 4b3b43c9..1e88cdec 100644 --- a/src/services/openaiAccountService.js +++ b/src/services/openaiAccountService.js @@ -440,10 +440,6 @@ async function deleteAccount(accountId) { throw new Error('Account not found') } - // 首先从所有分组中移除此账户 - const accountGroupService = require('./accountGroupService') - await accountGroupService.removeAccountFromAllGroups(accountId) - // 从 Redis 删除 const client = redisClient.getClientSafe() await client.del(`${OPENAI_ACCOUNT_KEY_PREFIX}${accountId}`)