From e0500f0530a05ed9bb444874b2d20e509a1960be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=BE=E5=BA=86=E9=9B=B7?= Date: Tue, 25 Nov 2025 19:06:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9AGemini=20OAuth=20?= =?UTF-8?q?=E8=B4=A6=E6=88=B7=20projectId=20=E9=99=8D=E7=BA=A7=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E7=BC=BA=E5=A4=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复 3 个端点未使用 tempProjectId 的问题: - /messages - /v1internal:generateContent - /v1internal:streamGenerateContent 优先级链:projectId -> tempProjectId -> 请求参数 -> null --- src/handlers/geminiHandlers.js | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/handlers/geminiHandlers.js b/src/handlers/geminiHandlers.js index 1e9a3968..7a95c0da 100644 --- a/src/handlers/geminiHandlers.js +++ b/src/handlers/geminiHandlers.js @@ -417,6 +417,9 @@ async function handleMessages(req, res) { } } else { // OAuth 账户:使用现有的 sendGeminiRequest + // 智能处理项目ID:优先使用配置的 projectId,降级到临时 tempProjectId + const effectiveProjectId = account.projectId || account.tempProjectId || null + geminiResponse = await sendGeminiRequest({ messages, model, @@ -427,7 +430,7 @@ async function handleMessages(req, res) { proxy: account.proxy, apiKeyId: apiKeyData.id, signal: abortController.signal, - projectId: account.projectId, + projectId: effectiveProjectId, accountId: account.id }) } @@ -1101,14 +1104,21 @@ async function handleGenerateContent(req, res) { const client = await geminiAccountService.getOauthClient(accessToken, refreshToken, proxyConfig) - // 智能处理项目ID - const effectiveProjectId = account.projectId || project || null + // 智能处理项目ID:优先使用配置的 projectId,降级到临时 tempProjectId,最后使用请求参数 + const effectiveProjectId = account.projectId || account.tempProjectId || project || null logger.info('📋 项目ID处理逻辑', { accountProjectId: account.projectId, + accountTempProjectId: account.tempProjectId, requestProjectId: project, effectiveProjectId, - decision: account.projectId ? '使用账户配置' : project ? '使用请求参数' : '不使用项目ID' + decision: account.projectId + ? '使用账户配置' + : account.tempProjectId + ? '使用临时项目ID' + : project + ? '使用请求参数' + : '不使用项目ID' }) const response = await geminiAccountService.generateContent( @@ -1281,14 +1291,21 @@ async function handleStreamGenerateContent(req, res) { const client = await geminiAccountService.getOauthClient(accessToken, refreshToken, proxyConfig) - // 智能处理项目ID - const effectiveProjectId = account.projectId || project || null + // 智能处理项目ID:优先使用配置的 projectId,降级到临时 tempProjectId,最后使用请求参数 + const effectiveProjectId = account.projectId || account.tempProjectId || project || null logger.info('📋 流式请求项目ID处理逻辑', { accountProjectId: account.projectId, + accountTempProjectId: account.tempProjectId, requestProjectId: project, effectiveProjectId, - decision: account.projectId ? '使用账户配置' : project ? '使用请求参数' : '不使用项目ID' + decision: account.projectId + ? '使用账户配置' + : account.tempProjectId + ? '使用临时项目ID' + : project + ? '使用请求参数' + : '不使用项目ID' }) const streamResponse = await geminiAccountService.generateContentStream(