fix(desktop): 解析 Google OAuth 客户端文件路径并更新示例与说明
Some checks failed
Secrets v3 CI / 检查 (push) Failing after 2m5s

This commit is contained in:
agent
2026-04-14 19:40:37 +08:00
parent 328962706b
commit e6bd2225cd
3 changed files with 49 additions and 8 deletions

View File

@@ -929,14 +929,52 @@ fn apply_mcp_config_to_all() -> AnyResult<()> {
Ok(())
}
fn workspace_root() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../..")
}
fn default_google_oauth_client_filename() -> &'static str {
"client_secret_738964258008-0svfo4g7ta347iedrf6r9see87a8u3hn.apps.googleusercontent.com.json"
}
fn resolve_google_oauth_client_path() -> AnyResult<PathBuf> {
let configured = std::env::var("GOOGLE_OAUTH_CLIENT_FILE").ok();
let mut candidates = Vec::new();
let repo_root = workspace_root();
if let Some(raw_path) = configured.as_deref().map(str::trim).filter(|value| !value.is_empty()) {
let path = PathBuf::from(raw_path);
if path.is_absolute() {
candidates.push(path);
} else {
if let Ok(cwd) = std::env::current_dir() {
candidates.push(cwd.join(&path));
}
candidates.push(repo_root.join(&path));
}
} else {
candidates.push(repo_root.join(default_google_oauth_client_filename()));
}
candidates.dedup();
candidates.into_iter().find(|path| path.exists()).with_context(|| {
let configured_hint = configured
.as_deref()
.map(str::trim)
.filter(|value| !value.is_empty())
.map(|value| format!("当前 GOOGLE_OAUTH_CLIENT_FILE={value}"))
.unwrap_or_else(|| "当前未设置 GOOGLE_OAUTH_CLIENT_FILE。".to_string());
format!(
"google oauth client file not found. {} 请把 {} 放到仓库根目录,或把 GOOGLE_OAUTH_CLIENT_FILE 设置为该文件的绝对路径",
configured_hint,
default_google_oauth_client_filename(),
)
})
}
fn load_google_desktop_client() -> AnyResult<GoogleDesktopClient> {
let configured = std::env::var("GOOGLE_OAUTH_CLIENT_FILE")
.map(PathBuf::from)
.unwrap_or_else(|_| {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("../../..")
.join("client_secret_738964258008-0svfo4g7ta347iedrf6r9see87a8u3hn.apps.googleusercontent.com.json")
});
let configured = resolve_google_oauth_client_path()?;
let raw = fs::read_to_string(&configured)
.with_context(|| format!("failed to read {}", configured.display()))?;
let parsed: GoogleDesktopClientFile =