feat(frontend): 支持 Gemini OAuth 类型选择 (Code Assist/AI Studio)

- CreateAccountModal.vue: 新增 OAuth 类型选择 UI
- ReAuthAccountModal.vue: 重授权支持选择类型
- OAuthAuthorizationFlow.vue: 新增 Project ID 输入框
- AccountTestModal.vue: Gemini 模型默认选择优化
- useGeminiOAuth.ts: OAuth 逻辑参数变更
- gemini.ts: API 调用更新
This commit is contained in:
ianshaw
2025-12-25 21:25:02 -08:00
parent 46cb82bac0
commit 09431cfc0b
6 changed files with 239 additions and 189 deletions

View File

@@ -10,6 +10,7 @@ export interface GeminiTokenInfo {
scope?: string
expires_at?: number | string
project_id?: string
oauth_type?: string
[key: string]: unknown
}
@@ -33,7 +34,8 @@ export function useGeminiOAuth() {
const generateAuthUrl = async (
proxyId: number | null | undefined,
redirectUri: string
projectId?: string | null,
oauthType?: string
): Promise<boolean> => {
loading.value = true
authUrl.value = ''
@@ -42,14 +44,11 @@ export function useGeminiOAuth() {
error.value = ''
try {
if (!redirectUri?.trim()) {
error.value = t('admin.accounts.oauth.gemini.missingRedirectUri')
appStore.showError(error.value)
return false
}
const payload: Record<string, unknown> = { redirect_uri: redirectUri.trim() }
const payload: Record<string, unknown> = {}
if (proxyId) payload.proxy_id = proxyId
const trimmedProjectID = projectId?.trim()
if (trimmedProjectID) payload.project_id = trimmedProjectID
if (oauthType) payload.oauth_type = oauthType
const response = await adminAPI.gemini.generateAuthUrl(payload as any)
authUrl.value = response.auth_url
@@ -69,11 +68,11 @@ export function useGeminiOAuth() {
code: string
sessionId: string
state: string
redirectUri: string
proxyId?: number | null
oauthType?: string
}): Promise<GeminiTokenInfo | null> => {
const code = params.code?.trim()
if (!code || !params.sessionId || !params.state || !params.redirectUri?.trim()) {
if (!code || !params.sessionId || !params.state) {
error.value = t('admin.accounts.oauth.gemini.missingExchangeParams')
return null
}
@@ -85,10 +84,10 @@ export function useGeminiOAuth() {
const payload: Record<string, unknown> = {
session_id: params.sessionId,
state: params.state,
code,
redirect_uri: params.redirectUri.trim()
code
}
if (params.proxyId) payload.proxy_id = params.proxyId
if (params.oauthType) payload.oauth_type = params.oauthType
const tokenInfo = await adminAPI.gemini.exchangeCode(payload as any)
return tokenInfo as GeminiTokenInfo
@@ -115,7 +114,8 @@ export function useGeminiOAuth() {
token_type: tokenInfo.token_type,
expires_at: expiresAt,
scope: tokenInfo.scope,
project_id: tokenInfo.project_id
project_id: tokenInfo.project_id,
oauth_type: tokenInfo.oauth_type
}
}