feat: 优化 Gemini OAuth 授权流程,使用固定的 localhost 回调地址

- 将 Gemini OAuth 回调地址固定为 http://localhost:45462
- 更新前端提示文字为"复制oauth后的链接"
- 实现自动提取 localhost:45462 链接中的 code 参数功能
- 删除不再需要的 web/auth_gemini 路由
- 添加详细的用户操作说明和错误处理提示
- 支持两种输入方式:完整链接或仅授权码

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
shaw
2025-07-22 11:42:54 +08:00
parent ed99043127
commit 11318c22b0
4 changed files with 74 additions and 192 deletions

View File

@@ -336,6 +336,13 @@ const app = createApp({
this.loadCurrentTabData();
},
immediate: false
},
'geminiOauthData.code': {
handler(newValue) {
if (newValue) {
this.handleGeminiAuthCodeInput(newValue);
}
}
}
},
@@ -1110,6 +1117,47 @@ const app = createApp({
}
},
// 处理 Gemini OAuth 授权码输入
handleGeminiAuthCodeInput(value, isUserTyping = false) {
if (!value || typeof value !== 'string') return;
const trimmedValue = value.trim();
// 如果内容为空,不处理
if (!trimmedValue) return;
// 检查是否是 URL 格式(包含 http:// 或 https://
const isUrl = trimmedValue.startsWith('http://') || trimmedValue.startsWith('https://');
// 如果是 URL 格式
if (isUrl) {
// 检查是否是正确的 localhost:45462 开头的 URL
if (trimmedValue.startsWith('http://localhost:45462')) {
try {
const url = new URL(trimmedValue);
const code = url.searchParams.get('code');
if (code) {
// 成功提取授权码
this.geminiOauthData.code = code;
this.showToast('成功提取授权码!', 'success', '提取成功');
console.log('Successfully extracted authorization code from URL');
} else {
// URL 中没有 code 参数
this.showToast('URL 中未找到授权码参数,请检查链接是否正确', 'error', '提取失败');
}
} catch (error) {
// URL 解析失败
console.error('Failed to parse URL:', error);
this.showToast('链接格式错误,请检查是否为完整的 URL', 'error', '解析失败');
}
} else {
// 错误的 URL不是 localhost:45462 开头)
this.showToast('请粘贴以 http://localhost:45462 开头的链接', 'error', '链接错误');
}
}
// 如果不是 URL保持原值兼容直接输入授权码
},
// 根据当前标签页加载数据
loadCurrentTabData() {