diff --git a/crates/dbx-core/src/lib.rs b/crates/dbx-core/src/lib.rs index 59c8d5d3b..36143057b 100644 --- a/crates/dbx-core/src/lib.rs +++ b/crates/dbx-core/src/lib.rs @@ -20,3 +20,5 @@ pub mod table_import; pub mod transfer; pub mod types; pub mod update; + +pub const GITHUB_PROXIES: &[&str] = &["https://update.hwdns.net/", "https://gh-proxy.org/", ""]; diff --git a/crates/dbx-core/src/update.rs b/crates/dbx-core/src/update.rs index b93c5aef6..b70d68a9c 100644 --- a/crates/dbx-core/src/update.rs +++ b/crates/dbx-core/src/update.rs @@ -1,10 +1,6 @@ use serde::{Deserialize, Serialize}; -const LATEST_JSON_URLS: &[&str] = &[ - "https://update.hwdns.net/https://github.com/t8y2/dbx/releases/latest/download/latest.json", - "https://gh-proxy.org/https://github.com/t8y2/dbx/releases/latest/download/latest.json", - "https://github.com/t8y2/dbx/releases/latest/download/latest.json", -]; +const LATEST_JSON_PATH: &str = "https://github.com/t8y2/dbx/releases/latest/download/latest.json"; const GITHUB_RELEASE_API_PREFIX: &str = "https://api.github.com/repos/t8y2/dbx/releases/tags/v"; const RELEASE_URL_PREFIX: &str = "https://github.com/t8y2/dbx/releases/tag/v"; @@ -40,9 +36,10 @@ pub async fn fetch_latest_release() -> Result { .build() .map_err(|e| format!("Failed to create HTTP client: {e}"))?; let mut last_err = String::new(); - for url in LATEST_JSON_URLS { + for proxy in crate::GITHUB_PROXIES { + let url = format!("{proxy}{LATEST_JSON_PATH}"); match client - .get(*url) + .get(&url) .header(reqwest::header::USER_AGENT, "dbx-update-checker") .send() .await diff --git a/src-tauri/src/commands/agents.rs b/src-tauri/src/commands/agents.rs index 7d4d03fc3..8832ad18a 100644 --- a/src-tauri/src/commands/agents.rs +++ b/src-tauri/src/commands/agents.rs @@ -5,13 +5,7 @@ use tauri::State; use dbx_core::agent_manager::{AgentDriverInfo, AgentManager, AgentRegistry, InstalledDriver}; use dbx_core::connection::AppState; -const REGISTRY_URLS: &[&str] = &[ - "https://update.hwdns.net/https://github.com/t8y2/dbx-agents/releases/latest/download/agent-registry.json", - "https://gh-proxy.org/https://github.com/t8y2/dbx-agents/releases/latest/download/agent-registry.json", - "https://github.com/t8y2/dbx-agents/releases/latest/download/agent-registry.json", -]; - -const DOWNLOAD_PROXIES: &[&str] = &["https://update.hwdns.net/", "https://gh-proxy.org/", ""]; +const REGISTRY_PATH: &str = "https://github.com/t8y2/dbx-agents/releases/latest/download/agent-registry.json"; #[tauri::command] pub async fn list_installed_agents(state: State<'_, Arc>) -> Result, String> { @@ -105,9 +99,10 @@ async fn fetch_registry() -> Result { .build() .map_err(|e| format!("Failed to create HTTP client: {e}"))?; let mut last_err = String::new(); - for url in REGISTRY_URLS { + for proxy in dbx_core::GITHUB_PROXIES { + let url = format!("{proxy}{REGISTRY_PATH}"); match client - .get(*url) + .get(&url) .header(reqwest::header::USER_AGENT, "dbx-agent-manager") .send() .await @@ -133,7 +128,7 @@ async fn download_with_proxy(url: &str, dest: &std::path::Path) -> Result<(), St .build() .map_err(|e| format!("Failed to create HTTP client: {e}"))?; let mut last_err = String::new(); - for proxy in DOWNLOAD_PROXIES { + for proxy in dbx_core::GITHUB_PROXIES { let full_url = format!("{proxy}{url}"); log::info!("[agent] downloading from {full_url}"); match client