修复:Gemini OAuth 账户 projectId 降级逻辑缺失

修复 3 个端点未使用 tempProjectId 的问题:
- /messages
- /v1internal:generateContent
- /v1internal:streamGenerateContent

优先级链:projectId -> tempProjectId -> 请求参数 -> null
This commit is contained in:
曾庆雷
2025-11-25 19:06:55 +08:00
parent 255b3a0a0d
commit e0500f0530

View File

@@ -417,6 +417,9 @@ async function handleMessages(req, res) {
} }
} else { } else {
// OAuth 账户:使用现有的 sendGeminiRequest // OAuth 账户:使用现有的 sendGeminiRequest
// 智能处理项目ID优先使用配置的 projectId降级到临时 tempProjectId
const effectiveProjectId = account.projectId || account.tempProjectId || null
geminiResponse = await sendGeminiRequest({ geminiResponse = await sendGeminiRequest({
messages, messages,
model, model,
@@ -427,7 +430,7 @@ async function handleMessages(req, res) {
proxy: account.proxy, proxy: account.proxy,
apiKeyId: apiKeyData.id, apiKeyId: apiKeyData.id,
signal: abortController.signal, signal: abortController.signal,
projectId: account.projectId, projectId: effectiveProjectId,
accountId: account.id accountId: account.id
}) })
} }
@@ -1101,14 +1104,21 @@ async function handleGenerateContent(req, res) {
const client = await geminiAccountService.getOauthClient(accessToken, refreshToken, proxyConfig) const client = await geminiAccountService.getOauthClient(accessToken, refreshToken, proxyConfig)
// 智能处理项目ID // 智能处理项目ID:优先使用配置的 projectId降级到临时 tempProjectId最后使用请求参数
const effectiveProjectId = account.projectId || project || null const effectiveProjectId = account.projectId || account.tempProjectId || project || null
logger.info('📋 项目ID处理逻辑', { logger.info('📋 项目ID处理逻辑', {
accountProjectId: account.projectId, accountProjectId: account.projectId,
accountTempProjectId: account.tempProjectId,
requestProjectId: project, requestProjectId: project,
effectiveProjectId, effectiveProjectId,
decision: account.projectId ? '使用账户配置' : project ? '使用请求参数' : '不使用项目ID' decision: account.projectId
? '使用账户配置'
: account.tempProjectId
? '使用临时项目ID'
: project
? '使用请求参数'
: '不使用项目ID'
}) })
const response = await geminiAccountService.generateContent( const response = await geminiAccountService.generateContent(
@@ -1281,14 +1291,21 @@ async function handleStreamGenerateContent(req, res) {
const client = await geminiAccountService.getOauthClient(accessToken, refreshToken, proxyConfig) const client = await geminiAccountService.getOauthClient(accessToken, refreshToken, proxyConfig)
// 智能处理项目ID // 智能处理项目ID:优先使用配置的 projectId降级到临时 tempProjectId最后使用请求参数
const effectiveProjectId = account.projectId || project || null const effectiveProjectId = account.projectId || account.tempProjectId || project || null
logger.info('📋 流式请求项目ID处理逻辑', { logger.info('📋 流式请求项目ID处理逻辑', {
accountProjectId: account.projectId, accountProjectId: account.projectId,
accountTempProjectId: account.tempProjectId,
requestProjectId: project, requestProjectId: project,
effectiveProjectId, effectiveProjectId,
decision: account.projectId ? '使用账户配置' : project ? '使用请求参数' : '不使用项目ID' decision: account.projectId
? '使用账户配置'
: account.tempProjectId
? '使用临时项目ID'
: project
? '使用请求参数'
: '不使用项目ID'
}) })
const streamResponse = await geminiAccountService.generateContentStream( const streamResponse = await geminiAccountService.generateContentStream(