This commit is contained in:
SunSeekerX
2026-01-01 12:42:47 +08:00
parent 666b0120b7
commit d8a33f9aa7
18 changed files with 335 additions and 122 deletions

View File

@@ -18,7 +18,9 @@ class AccountGroupService {
async ensureReverseIndexes() {
try {
const client = redis.getClientSafe()
if (!client) return
if (!client) {
return
}
// 检查是否已迁移
const migrated = await client.get(this.REVERSE_INDEX_MIGRATED_KEY)
@@ -39,10 +41,14 @@ class AccountGroupService {
for (const groupId of allGroupIds) {
const group = await client.hgetall(`${this.GROUP_PREFIX}${groupId}`)
if (!group || !group.platform) continue
if (!group || !group.platform) {
continue
}
const members = await client.smembers(`${this.GROUP_MEMBERS_PREFIX}${groupId}`)
if (members.length === 0) continue
if (members.length === 0) {
continue
}
const pipeline = client.pipeline()
for (const accountId of members) {

View File

@@ -71,7 +71,9 @@ class ApiKeyIndexService {
* 扫描所有 API Key确保 hash -> keyId 映射存在
*/
async rebuildHashMap() {
if (!this.redis) return
if (!this.redis) {
return
}
try {
const client = this.redis.getClientSafe()
@@ -187,7 +189,9 @@ class ApiKeyIndexService {
const pipeline = client.pipeline()
for (const apiKey of apiKeys) {
if (!apiKey || !apiKey.id) continue
if (!apiKey || !apiKey.id) {
continue
}
const keyId = apiKey.id
const createdAt = apiKey.createdAt ? new Date(apiKey.createdAt).getTime() : 0
@@ -249,7 +253,9 @@ class ApiKeyIndexService {
* 添加单个 API Key 到索引
*/
async addToIndex(apiKey) {
if (!this.redis || !apiKey || !apiKey.id) return
if (!this.redis || !apiKey || !apiKey.id) {
return
}
try {
const client = this.redis.getClientSafe()
@@ -297,7 +303,9 @@ class ApiKeyIndexService {
* 更新索引(状态、名称、标签变化时调用)
*/
async updateIndex(keyId, updates, oldData = {}) {
if (!this.redis || !keyId) return
if (!this.redis || !keyId) {
return
}
try {
const client = this.redis.getClientSafe()
@@ -376,7 +384,9 @@ class ApiKeyIndexService {
* 从索引中移除 API Key
*/
async removeFromIndex(keyId, oldData = {}) {
if (!this.redis || !keyId) return
if (!this.redis || !keyId) {
return
}
try {
const client = this.redis.getClientSafe()
@@ -598,7 +608,9 @@ class ApiKeyIndexService {
* 更新 lastUsedAt 索引(供 recordUsage 调用)
*/
async updateLastUsedAt(keyId, lastUsedAt) {
if (!this.redis || !keyId) return
if (!this.redis || !keyId) {
return
}
try {
const client = this.redis.getClientSafe()

View File

@@ -921,7 +921,9 @@ class ApiKeyService {
return keyIds
.map((id, i) => {
const [err, fields] = results[i]
if (err) return null
if (err) {
return null
}
return {
id,
claudeAccountId: fields[0] || null,

View File

@@ -127,7 +127,7 @@ class BedrockAccountService {
// 📋 获取所有账户列表
async getAllAccounts() {
try {
const client = redis.getClientSafe()
const _client = redis.getClientSafe()
const accountIds = await redis.getAllIdsByIndex(
'bedrock_account:index',
'bedrock_account:*',

View File

@@ -2,7 +2,7 @@ const { v4: uuidv4 } = require('uuid')
const ProxyHelper = require('../utils/proxyHelper')
const redis = require('../models/redis')
const logger = require('../utils/logger')
const config = require('../../config/config')
// const config = require('../../config/config')
const { createEncryptor } = require('../utils/commonHelper')
class CcrAccountService {

View File

@@ -2,7 +2,7 @@ const { v4: uuidv4 } = require('uuid')
const crypto = require('crypto')
const axios = require('axios')
const redis = require('../models/redis')
const config = require('../../config/config')
// const config = require('../../config/config')
const logger = require('../utils/logger')
const { maskToken } = require('../utils/tokenMask')
const ProxyHelper = require('../utils/proxyHelper')

View File

@@ -1,7 +1,7 @@
const redisClient = require('../models/redis')
const { v4: uuidv4 } = require('uuid')
const https = require('https')
const config = require('../../config/config')
// const config = require('../../config/config')
const logger = require('../utils/logger')
const { OAuth2Client } = require('google-auth-library')
const { maskToken } = require('../utils/tokenMask')
@@ -19,6 +19,8 @@ const { createEncryptor } = require('../utils/commonHelper')
// Gemini 账户键前缀
const GEMINI_ACCOUNT_KEY_PREFIX = 'gemini_account:'
const SHARED_GEMINI_ACCOUNTS_KEY = 'shared_gemini_accounts'
const ACCOUNT_SESSION_MAPPING_PREFIX = 'gemini_session_account_mapping:'
// Gemini CLI OAuth 配置 - 这些是公开的 Gemini CLI 凭据
const OAUTH_CLIENT_ID = '681255809395-oo8ft2oprdrnp9e3aqf6av3hmdib135j.apps.googleusercontent.com'
const OAUTH_CLIENT_SECRET = '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'
@@ -572,7 +574,7 @@ async function deleteAccount(accountId) {
// 获取所有账户
async function getAllAccounts() {
const client = redisClient.getClientSafe()
const _client = redisClient.getClientSafe()
const accountIds = await redisClient.getAllIdsByIndex(
'gemini_account:index',
`${GEMINI_ACCOUNT_KEY_PREFIX}*`,

View File

@@ -666,7 +666,7 @@ async function deleteAccount(accountId) {
// 获取所有账户
async function getAllAccounts() {
const client = redisClient.getClientSafe()
const _client = redisClient.getClientSafe()
const accountIds = await redisClient.getAllIdsByIndex(
'openai:account:index',
`${OPENAI_ACCOUNT_KEY_PREFIX}*`,

View File

@@ -201,7 +201,9 @@ class OpenAIResponsesAccountService {
`${this.ACCOUNT_KEY_PREFIX}*`,
/^openai_responses_account:(.+)$/
)
if (accountIds.length === 0) return []
if (accountIds.length === 0) {
return []
}
const keys = accountIds.map((id) => `${this.ACCOUNT_KEY_PREFIX}${id}`)
// Pipeline 批量查询所有账户数据
@@ -210,11 +212,15 @@ class OpenAIResponsesAccountService {
const results = await pipeline.exec()
const accounts = []
results.forEach(([err, accountData], index) => {
if (err || !accountData || !accountData.id) return
results.forEach(([err, accountData], _index) => {
if (err || !accountData || !accountData.id) {
return
}
// 过滤非活跃账户
if (!includeInactive && accountData.isActive !== 'true') return
if (!includeInactive && accountData.isActive !== 'true') {
return
}
// 隐藏敏感信息
accountData.apiKey = '***'