Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

feat: use race_download with R2 for agent/JRE downloads

t8y2242720cc3cf2
diff --git a/crates/dbx-core/src/update.rs b/crates/dbx-core/src/update.rs
index bba49c4f96..57c01420c3 100644
--- a/crates/dbx-core/src/update.rs
+++ b/crates/dbx-core/src/update.rs
@@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
const LATEST_JSON_PATH: &str = "https://github.com/t8y2/dbx/releases/latest/download/latest.json";
+const LATEST_JSON_R2_PATH: &str = "releases/latest/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";
@@ -36,7 +37,7 @@ pub async fn fetch_latest_release() -> Result<TauriRelease, String> {
.build()
.map_err(|e| format!("Failed to create HTTP client: {e}"))?;
- let resp = crate::race_github_proxies(&client, LATEST_JSON_PATH, "dbx-update-checker")
+ let resp = crate::race_download(&client, LATEST_JSON_PATH, LATEST_JSON_R2_PATH, "dbx-update-checker")
.await
.map_err(|e| format!("Failed to check updates: {e}"))?;
diff --git a/src-tauri/src/commands/agents.rs b/src-tauri/src/commands/agents.rs
index c6a446836b..4211f95ca0 100644
--- a/src-tauri/src/commands/agents.rs
+++ b/src-tauri/src/commands/agents.rs
@@ -9,6 +9,7 @@ use dbx_core::agent_manager::{
use dbx_core::connection::AppState;
const REGISTRY_PATH: &str = "https://github.com/t8y2/dbx-agents/releases/latest/download/agent-registry.json";
+const REGISTRY_R2_PATH: &str = "agents/agent-registry.json";
static REGISTRY_CACHE: std::sync::LazyLock<Mutex<Option<(std::time::Instant, AgentRegistry)>>> =
std::sync::LazyLock::new(|| Mutex::new(None));
@@ -104,7 +105,15 @@ pub async fn install_agent(
"step": "jre", "downloaded": 0u64, "total": platform_jre.size,
}),
);
- download_with_progress(&app, "jre", &platform_jre.url, &jre_archive, platform_jre.size).await?;
+ download_with_progress(
+ &app,
+ "jre",
+ &platform_jre.url,
+ &github_url_to_r2_path(&platform_jre.url, "jre"),
+ &jre_archive,
+ platform_jre.size,
+ )
+ .await?;
let _ = app.emit(
"agent-install-progress",
serde_json::json!({
@@ -122,7 +131,15 @@ pub async fn install_agent(
"step": "driver", "downloaded": 0u64, "total": driver.jar.size,
}),
);
- download_with_progress(&app, "driver", &driver.jar.url, &jar_path, driver.jar.size).await?;
+ download_with_progress(
+ &app,
+ "driver",
+ &driver.jar.url,
+ &github_url_to_r2_path(&driver.jar.url, "driver"),
+ &jar_path,
+ driver.jar.size,
+ )
+ .await?;
let mut local_state = am.load_state();
if let Some(jre_info) = registry.resolve_jre(jre_key) {
@@ -175,7 +192,15 @@ pub async fn upgrade_all_agents(app: tauri::AppHandle, state: State<'_, Arc<AppS
"db_type": db_type, "current": current, "total_drivers": total_drivers,
}),
);
- download_with_progress(&app, "jre", &platform_jre.url, &jre_archive, platform_jre.size).await?;
+ download_with_progress(
+ &app,
+ "jre",
+ &platform_jre.url,
+ &github_url_to_r2_path(&platform_jre.url, "jre"),
+ &jre_archive,
+ platform_jre.size,
+ )
+ .await?;
let _ = app.emit(
"agent-install-progress",
serde_json::json!({
@@ -195,7 +220,15 @@ pub async fn upgrade_all_agents(app: tauri::AppHandle, state: State<'_, Arc<AppS
"db_type": db_type, "current": current, "total_drivers": total_drivers,
}),
);
- download_with_progress(&app, "driver", &driver.jar.url, &jar_path, driver.jar.size).await?;
+ download_with_progress(
+ &app,
+ "driver",
+ &driver.jar.url,
+ &github_url_to_r2_path(&driver.jar.url, "driver"),
+ &jar_path,
+ driver.jar.size,
+ )
+ .await?;
let mut local_state = am.load_state();
if let Some(jre_info) = registry.resolve_jre(jre_key) {
@@ -311,7 +344,15 @@ pub async fn reinstall_jre(
let platform_jre =
jre_info.platforms.get(platform).ok_or_else(|| format!("No JRE {key} available for platform: {platform}"))?;
let jre_archive = am.base_dir().join("jre-download.tar.gz");
- download_with_progress(&app, "jre", &platform_jre.url, &jre_archive, platform_jre.size).await?;
+ download_with_progress(
+ &app,
+ "jre",
+ &platform_jre.url,
+ &github_url_to_r2_path(&platform_jre.url, "jre"),
+ &jre_archive,
+ platform_jre.size,
+ )
+ .await?;
extract_archive(&jre_archive, &jre_dir)?;
std::fs::remove_file(&jre_archive).ok();
let mut local_state = am.load_state();
@@ -334,7 +375,7 @@ async fn fetch_registry() -> Result<AgentRegistry, String> {
.timeout(std::time::Duration::from_secs(10))
.build()
.map_err(|e| format!("Failed to create HTTP client: {e}"))?;
- let resp = dbx_core::race_github_proxies(&client, REGISTRY_PATH, "dbx-agent-manager")
+ let resp = dbx_core::race_download(&client, REGISTRY_PATH, REGISTRY_R2_PATH, "dbx-agent-manager")
.await
.map_err(|e| format!("Failed to fetch agent registry: {e}"))?;
let reg: AgentRegistry = resp.json().await.map_err(|e| format!("Failed to parse registry: {e}"))?;
@@ -342,10 +383,20 @@ async fn fetch_registry() -> Result<AgentRegistry, String> {
Ok(reg)
}
+fn github_url_to_r2_path(github_url: &str, category: &str) -> String {
+ let filename = github_url.rsplit('/').next().unwrap_or(github_url);
+ match category {
+ "jre" => format!("agents/jre/{filename}"),
+ "driver" => format!("agents/drivers/{filename}"),
+ _ => format!("agents/{filename}"),
+ }
+}
+
async fn download_with_progress(
app: &tauri::AppHandle,
step: &str,
url: &str,
+ r2_path: &str,
dest: &std::path::Path,
total_size: u64,
) -> Result<(), String> {
@@ -357,7 +408,7 @@ async fn download_with_progress(
.build()
.map_err(|e| format!("Failed to create HTTP client: {e}"))?;
- let resp = dbx_core::race_github_proxies(&client, url, "dbx-agent-manager")
+ let resp = dbx_core::race_download(&client, url, r2_path, "dbx-agent-manager")
.await
.map_err(|e| format!("Failed to download {url}: {e}"))?;