mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-23 17:49:16 +00:00
仅对个人账户调用 tokeninfo/userinfo 接口
- 添加 projectId 非空判断,减少对企业账户的影响 - 优化错误日志级别为 warn
This commit is contained in:
@@ -381,13 +381,18 @@ function handleSimpleEndpoint(apiMethod) {
|
|||||||
let proxyConfig = null
|
let proxyConfig = null
|
||||||
if (account.proxy) {
|
if (account.proxy) {
|
||||||
try {
|
try {
|
||||||
proxyConfig = typeof account.proxy === 'string' ? JSON.parse(account.proxy) : account.proxy
|
proxyConfig =
|
||||||
|
typeof account.proxy === 'string' ? JSON.parse(account.proxy) : account.proxy
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.warn('Failed to parse proxy configuration:', e)
|
logger.warn('Failed to parse proxy configuration:', e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const client = await geminiAccountService.getOauthClient(accessToken, refreshToken, proxyConfig)
|
const client = await geminiAccountService.getOauthClient(
|
||||||
|
accessToken,
|
||||||
|
refreshToken,
|
||||||
|
proxyConfig
|
||||||
|
)
|
||||||
|
|
||||||
// 直接转发请求体,不做特殊处理
|
// 直接转发请求体,不做特殊处理
|
||||||
const response = await geminiAccountService.forwardToCodeAssist(
|
const response = await geminiAccountService.forwardToCodeAssist(
|
||||||
@@ -1080,7 +1085,11 @@ router.post('/v1internal\\:onboardUser', authenticateApiKey, handleOnboardUser)
|
|||||||
router.post('/v1internal\\:countTokens', authenticateApiKey, handleCountTokens)
|
router.post('/v1internal\\:countTokens', authenticateApiKey, handleCountTokens)
|
||||||
router.post('/v1internal\\:generateContent', authenticateApiKey, handleGenerateContent)
|
router.post('/v1internal\\:generateContent', authenticateApiKey, handleGenerateContent)
|
||||||
router.post('/v1internal\\:streamGenerateContent', authenticateApiKey, handleStreamGenerateContent)
|
router.post('/v1internal\\:streamGenerateContent', authenticateApiKey, handleStreamGenerateContent)
|
||||||
router.post('/v1internal\\:listExperiments', authenticateApiKey, handleSimpleEndpoint('listExperiments'))
|
router.post(
|
||||||
|
'/v1internal\\:listExperiments',
|
||||||
|
authenticateApiKey,
|
||||||
|
handleSimpleEndpoint('listExperiments')
|
||||||
|
)
|
||||||
|
|
||||||
// v1beta 版本的端点 - 支持动态模型名称
|
// v1beta 版本的端点 - 支持动态模型名称
|
||||||
router.post('/v1beta/models/:modelName\\:loadCodeAssist', authenticateApiKey, handleLoadCodeAssist)
|
router.post('/v1beta/models/:modelName\\:loadCodeAssist', authenticateApiKey, handleLoadCodeAssist)
|
||||||
|
|||||||
@@ -1088,9 +1088,7 @@ async function forwardToCodeAssist(client, apiMethod, requestBody, proxyConfig =
|
|||||||
axiosConfig.httpAgent = proxyAgent
|
axiosConfig.httpAgent = proxyAgent
|
||||||
axiosConfig.httpsAgent = proxyAgent
|
axiosConfig.httpsAgent = proxyAgent
|
||||||
axiosConfig.proxy = false
|
axiosConfig.proxy = false
|
||||||
logger.info(
|
logger.info(`🌐 Using proxy for ${apiMethod}: ${ProxyHelper.getProxyDescription(proxyConfig)}`)
|
||||||
`🌐 Using proxy for ${apiMethod}: ${ProxyHelper.getProxyDescription(proxyConfig)}`
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
logger.debug(`🌐 No proxy configured for ${apiMethod}`)
|
logger.debug(`🌐 No proxy configured for ${apiMethod}`)
|
||||||
}
|
}
|
||||||
@@ -1109,7 +1107,9 @@ async function loadCodeAssist(client, projectId = null, proxyConfig = null) {
|
|||||||
|
|
||||||
const { token } = await client.getAccessToken()
|
const { token } = await client.getAccessToken()
|
||||||
const proxyAgent = ProxyHelper.createProxyAgent(proxyConfig)
|
const proxyAgent = ProxyHelper.createProxyAgent(proxyConfig)
|
||||||
|
// 🔍 只有个人账户(无 projectId)才需要调用 tokeninfo/userinfo
|
||||||
|
// 这些调用有助于 Google 获取临时 projectId
|
||||||
|
if (!projectId) {
|
||||||
const tokenInfoConfig = {
|
const tokenInfoConfig = {
|
||||||
url: 'https://oauth2.googleapis.com/tokeninfo',
|
url: 'https://oauth2.googleapis.com/tokeninfo',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -1131,7 +1131,7 @@ async function loadCodeAssist(client, projectId = null, proxyConfig = null) {
|
|||||||
await axios(tokenInfoConfig)
|
await axios(tokenInfoConfig)
|
||||||
logger.info('📋 tokeninfo 接口验证成功')
|
logger.info('📋 tokeninfo 接口验证成功')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.info('tokeninfo 接口获取失败', error)
|
logger.warn('⚠️ tokeninfo 接口调用失败:', error.message)
|
||||||
}
|
}
|
||||||
|
|
||||||
const userInfoConfig = {
|
const userInfoConfig = {
|
||||||
@@ -1154,7 +1154,8 @@ async function loadCodeAssist(client, projectId = null, proxyConfig = null) {
|
|||||||
await axios(userInfoConfig)
|
await axios(userInfoConfig)
|
||||||
logger.info('📋 userinfo 接口获取成功')
|
logger.info('📋 userinfo 接口获取成功')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.info('userinfo 接口获取失败', error)
|
logger.warn('⚠️ userinfo 接口调用失败:', error.message)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建ClientMetadata
|
// 创建ClientMetadata
|
||||||
|
|||||||
Reference in New Issue
Block a user