diff --git a/apps/desktop/src/components/config/DriverStoreDialog.vue b/apps/desktop/src/components/config/DriverStoreDialog.vue index 82abc0dc36..44d2da885e 100644 --- a/apps/desktop/src/components/config/DriverStoreDialog.vue +++ b/apps/desktop/src/components/config/DriverStoreDialog.vue @@ -166,6 +166,7 @@ const javaRuntimeConfig = ref({ mode: "managed", custom_java_ const customJavaPath = ref(""); const savingJavaRuntime = ref(false); const driverStoreUsage = ref(null); +const clearingDownloadCache = ref(false); const runtimeSummary = ref(null); const runtimeLoading = ref(false); const runtimeError = ref(""); @@ -215,6 +216,7 @@ function resetInstallProgress() { } const updatableCount = computed(() => (props.updateNotificationsEnabled ? drivers.value.filter((d) => d.update_available).length : 0)); +const downloadCacheBytes = computed(() => Number(driverStoreUsage.value?.download_cache_bytes || 0)); const usageSummary = computed(() => { const usage = driverStoreUsage.value; if (!usage) return []; @@ -222,10 +224,12 @@ const usageSummary = computed(() => { { key: "total", label: t("driverStore.usageTotalLabel"), bytes: usage.total_bytes }, { key: "jre", label: t("driverStore.usageManagedJre"), bytes: usage.jre_bytes }, { key: "agent", label: t("driverStore.usageAgentDrivers"), bytes: usage.agent_driver_bytes }, + { key: "download-cache", label: t("driverStore.usageDownloadCache"), bytes: usage.download_cache_bytes || 0 }, { key: "jdbc-plugin", label: t("driverStore.usageJdbcPlugin"), bytes: usage.jdbc_plugin_bytes }, { key: "jdbc-driver", label: t("driverStore.usageJdbcDriverJars"), bytes: usage.jdbc_driver_bytes }, ]; }); +const canClearDownloadCache = computed(() => !clearingDownloadCache.value && installing.value === null && !upgradingAll.value && reinstallingJre.value === null && downloadCacheBytes.value > 0); const jreUsageByKey = computed(() => { const map = new Map(); for (const item of driverStoreUsage.value?.jres || []) { @@ -807,6 +811,20 @@ async function loadDriverStoreUsage() { } } +async function clearDownloadCache() { + if (!canClearDownloadCache.value) return; + clearingDownloadCache.value = true; + try { + await api.clearDriverDownloadCache(); + await loadDriverStoreUsage(); + toast(t("driverStore.downloadCacheClearSuccess")); + } catch (e: any) { + toast(t("driverStore.downloadCacheClearFailed", { error: e?.message || String(e) }), 5000); + } finally { + clearingDownloadCache.value = false; + } +} + async function loadJdbcPluginStatus() { try { jdbcPluginStatus.value = await api.jdbcPluginStatus(); @@ -1293,11 +1311,18 @@ watch(driverStoreTab, (tab) => {
{{ t("driverStore.usageTitle") }}
-
- {{ usageSummary.length ? t("driverStore.usageTotal", { size: formatBytes(usageSummary[0].bytes) }) : t("driverStore.calculating") }} +
+
+ {{ usageSummary.length ? t("driverStore.usageTotal", { size: formatBytes(usageSummary[0].bytes) }) : t("driverStore.calculating") }} +
+
-
+
{{ item.label }}
{{ formatBytes(item.bytes) }}
diff --git a/apps/desktop/src/i18n/locales/en.ts b/apps/desktop/src/i18n/locales/en.ts index 7d6b065cb0..b10e049487 100644 --- a/apps/desktop/src/i18n/locales/en.ts +++ b/apps/desktop/src/i18n/locales/en.ts @@ -3223,8 +3223,12 @@ export default { calculating: "Calculating...", usageManagedJre: "Managed JRE", usageAgentDrivers: "Built-in driver agents", + usageDownloadCache: "Download cache", usageJdbcPlugin: "JDBC plugin", usageJdbcDriverJars: "JDBC driver JARs", + clearDownloadCache: "Clear cache", + downloadCacheClearSuccess: "Download cache cleared", + downloadCacheClearFailed: "Failed to clear download cache: {error}", offlineDownloadHint: "For air-gapped environments, download offline driver packages on an internet-connected machine, then import them here.", offlineDownloadLink: "Offline driver downloads", searchDrivers: "Search driver name, type, version...", diff --git a/apps/desktop/src/i18n/locales/es.ts b/apps/desktop/src/i18n/locales/es.ts index 4796598f4b..3eaeccd92d 100644 --- a/apps/desktop/src/i18n/locales/es.ts +++ b/apps/desktop/src/i18n/locales/es.ts @@ -3124,8 +3124,12 @@ export default withEnglishFallback({ calculating: "Calculando...", usageManagedJre: "JRE administrado", usageAgentDrivers: "Agentes de driver integrados", + usageDownloadCache: "Caché de descargas", usageJdbcPlugin: "Plugin JDBC", usageJdbcDriverJars: "JARs de driver JDBC", + clearDownloadCache: "Limpiar caché", + downloadCacheClearSuccess: "Caché de descargas limpiada", + downloadCacheClearFailed: "Error al limpiar la caché de descargas: {error}", offlineDownloadHint: "Para entornos sin conexión a internet, descarga los paquetes de drivers offline en una máquina con conexión, luego impórtalos aquí.", offlineDownloadLink: "Descargas de drivers offline", searchDrivers: "Buscar nombre de driver, tipo, versión...", diff --git a/apps/desktop/src/i18n/locales/it.ts b/apps/desktop/src/i18n/locales/it.ts index 9a688d9db7..9d4e59b410 100644 --- a/apps/desktop/src/i18n/locales/it.ts +++ b/apps/desktop/src/i18n/locales/it.ts @@ -3122,8 +3122,12 @@ export default withEnglishFallback({ calculating: "Calcolo in corso...", usageManagedJre: "JRE gestito", usageAgentDrivers: "Agenti driver integrati", + usageDownloadCache: "Cache download", usageJdbcPlugin: "Plugin JDBC", usageJdbcDriverJars: "JAR dei driver JDBC", + clearDownloadCache: "Pulisci cache", + downloadCacheClearSuccess: "Cache download pulita", + downloadCacheClearFailed: "Pulizia cache download non riuscita: {error}", offlineDownloadHint: "Per ambienti air-gapped, scarica i pacchetti driver offline su una macchina connessa a Internet, quindi importali qui.", offlineDownloadLink: "Download driver offline", searchDrivers: "Cerca nome driver, tipo, versione...", diff --git a/apps/desktop/src/i18n/locales/ja.ts b/apps/desktop/src/i18n/locales/ja.ts index 18aeb7253f..c9e6892ad0 100644 --- a/apps/desktop/src/i18n/locales/ja.ts +++ b/apps/desktop/src/i18n/locales/ja.ts @@ -3122,8 +3122,12 @@ export default withEnglishFallback({ calculating: "計算中...", usageManagedJre: "管理対象JRE", usageAgentDrivers: "組み込みドライバーエージェント", + usageDownloadCache: "ダウンロードキャッシュ", usageJdbcPlugin: "JDBCプラグイン", usageJdbcDriverJars: "JDBCドライバーJAR", + clearDownloadCache: "キャッシュを削除", + downloadCacheClearSuccess: "ダウンロードキャッシュを削除しました", + downloadCacheClearFailed: "ダウンロードキャッシュの削除に失敗しました: {error}", offlineDownloadHint: "エアギャップ環境の場合は、インターネット接続されたマシンでオフラインドライバーパッケージをダウンロードし、ここでインポートしてください。", offlineDownloadLink: "オフラインドライバーダウンロード", searchDrivers: "ドライバー名、タイプ、バージョンを検索...", diff --git a/apps/desktop/src/i18n/locales/pt-BR.ts b/apps/desktop/src/i18n/locales/pt-BR.ts index 24ec58291d..bb29ce2efe 100644 --- a/apps/desktop/src/i18n/locales/pt-BR.ts +++ b/apps/desktop/src/i18n/locales/pt-BR.ts @@ -3123,8 +3123,12 @@ export default withEnglishFallback({ calculating: "Calculando...", usageManagedJre: "JRE gerenciada", usageAgentDrivers: "Agentes de driver integrados", + usageDownloadCache: "Cache de downloads", usageJdbcPlugin: "Plugin JDBC", usageJdbcDriverJars: "JARs de driver JDBC", + clearDownloadCache: "Limpar cache", + downloadCacheClearSuccess: "Cache de downloads limpo", + downloadCacheClearFailed: "Falha ao limpar cache de downloads: {error}", offlineDownloadHint: "Para ambientes sem internet, baixe pacotes de driver offline em uma máquina com acesso à internet e importe-os aqui.", offlineDownloadLink: "Downloads de driver offline", searchDrivers: "Pesquisar nome, tipo, versão do driver...", diff --git a/apps/desktop/src/i18n/locales/zh-CN.ts b/apps/desktop/src/i18n/locales/zh-CN.ts index b397bdd5e3..3776eda55e 100644 --- a/apps/desktop/src/i18n/locales/zh-CN.ts +++ b/apps/desktop/src/i18n/locales/zh-CN.ts @@ -3223,8 +3223,12 @@ export default withEnglishFallback({ calculating: "统计中...", usageManagedJre: "托管 JRE", usageAgentDrivers: "内置驱动 Agent", + usageDownloadCache: "下载缓存", usageJdbcPlugin: "JDBC 插件", usageJdbcDriverJars: "JDBC 驱动 JAR", + clearDownloadCache: "清理缓存", + downloadCacheClearSuccess: "下载缓存已清理", + downloadCacheClearFailed: "下载缓存清理失败: {error}", offlineDownloadHint: "内网环境可先在有网机器下载离线驱动包,再回到这里导入。", offlineDownloadLink: "离线驱动下载", searchDrivers: "搜索驱动名称、类型、版本...", diff --git a/apps/desktop/src/i18n/locales/zh-TW.ts b/apps/desktop/src/i18n/locales/zh-TW.ts index c7e5960aff..0734a331ea 100644 --- a/apps/desktop/src/i18n/locales/zh-TW.ts +++ b/apps/desktop/src/i18n/locales/zh-TW.ts @@ -3023,8 +3023,12 @@ export default withEnglishFallback({ calculating: "統計中……", usageManagedJre: "託管 JRE", usageAgentDrivers: "內建驅動程式 Agent", + usageDownloadCache: "下載快取", usageJdbcPlugin: "JDBC 外掛程式", usageJdbcDriverJars: "JDBC 驅動程式 JAR", + clearDownloadCache: "清理快取", + downloadCacheClearSuccess: "下載快取已清理", + downloadCacheClearFailed: "下載快取清理失敗: {error}", javaRuntimeSaved: "Java 執行環境設定已儲存", javaRuntimeSaveFailed: "Java 執行環境設定失敗: {error}", chooseJavaExecutable: "選擇 Java 可執行檔", diff --git a/apps/desktop/src/lib/backend/api.ts b/apps/desktop/src/lib/backend/api.ts index 3e348a8876..766c6e8226 100644 --- a/apps/desktop/src/lib/backend/api.ts +++ b/apps/desktop/src/lib/backend/api.ts @@ -76,6 +76,7 @@ export const uninstallJdbcPlugin = forward("uninstallJdbcPlugin"); export const listInstalledAgentsLocal = forward("listInstalledAgentsLocal"); export const listInstalledAgents = forward("listInstalledAgents"); export const getDriverStoreUsage = forward("getDriverStoreUsage"); +export const clearDriverDownloadCache = forward("clearDriverDownloadCache"); export const getDriverRuntimeSummary = forward("getDriverRuntimeSummary"); export const stopDriverRuntime = forward("stopDriverRuntime"); export const restartDriverRuntime = forward("restartDriverRuntime"); diff --git a/apps/desktop/src/lib/backend/http.ts b/apps/desktop/src/lib/backend/http.ts index 1382252a3b..8a9a1db4c5 100644 --- a/apps/desktop/src/lib/backend/http.ts +++ b/apps/desktop/src/lib/backend/http.ts @@ -337,6 +337,10 @@ export async function getDriverStoreUsage(): Promise { return get("/api/agents/storage-usage"); } +export async function clearDriverDownloadCache(): Promise { + await del("/api/agents/download-cache"); +} + export async function getDriverRuntimeSummary(): Promise { return get("/api/agents/runtime"); } diff --git a/apps/desktop/src/lib/backend/tauri.ts b/apps/desktop/src/lib/backend/tauri.ts index 7c12f10acf..5e120ad1ec 100644 --- a/apps/desktop/src/lib/backend/tauri.ts +++ b/apps/desktop/src/lib/backend/tauri.ts @@ -1108,6 +1108,10 @@ export async function getDriverStoreUsage(): Promise { return invoke("get_driver_store_usage"); } +export async function clearDriverDownloadCache(): Promise { + return invoke("clear_driver_download_cache"); +} + export async function getDriverRuntimeSummary(): Promise { return invoke("get_driver_runtime_summary"); } diff --git a/apps/desktop/vite.config.ts b/apps/desktop/vite.config.ts index 9ae10750a0..ea88e10cc0 100644 --- a/apps/desktop/vite.config.ts +++ b/apps/desktop/vite.config.ts @@ -58,6 +58,7 @@ function normalizeViteBase(value: string | undefined): string { const viteBase = normalizeViteBase(configuredBasePath); const publicBasePath = viteBase.startsWith("/") ? viteBase.replace(/\/+$/, "") : ""; const apiProxyPath = publicBasePath ? `${publicBasePath}/api` : "/api"; +const backendUrl = process.env.DBX_BACKEND_URL || "http://localhost:4224"; export default defineConfig(async () => ({ root: __dirname, @@ -91,7 +92,7 @@ export default defineConfig(async () => ({ : undefined, proxy: { [apiProxyPath]: { - target: "http://localhost:4224", + target: backendUrl, changeOrigin: true, ws: true, rewrite: publicBasePath ? (requestPath) => requestPath.slice(publicBasePath.length) || "/" : undefined, diff --git a/crates/dbx-core/src/agent_service.rs b/crates/dbx-core/src/agent_service.rs index af72c0342d..7b36e10d18 100644 --- a/crates/dbx-core/src/agent_service.rs +++ b/crates/dbx-core/src/agent_service.rs @@ -406,6 +406,10 @@ pub async fn uninstall_agent_driver(am: &AgentManager, db_type: &str) -> Result< Ok(()) } +pub fn clear_agent_download_cache(am: &AgentManager) -> Result<(), String> { + remove_download_cache_entries(am, |_| true, "download cache") +} + pub async fn uninstall_agent_jre(am: &AgentManager, jre_key: &str) -> Result<(), String> { let local_state = am.load_state(); let dependents: Vec<&str> = local_state @@ -468,6 +472,7 @@ pub async fn reinstall_agent_jre( let mut local_state = am.load_state(); local_state.jre_versions.insert(jre_key.to_string(), jre_info.version.clone()); am.save_state(&local_state)?; + cleanup_jre_download_cache_after_success(am, jre_key); progress(AgentProgressEvent::step("done")); Ok(()) } @@ -572,6 +577,7 @@ async fn ensure_jre_from_registry( replace_old_jre_dir(am, &jre_dir)?; extract_tar_gz(&jre_archive, &jre_dir)?; std::fs::remove_file(&jre_archive).ok(); + cleanup_jre_download_cache_after_success(am, jre_key); Ok(()) } @@ -683,6 +689,7 @@ async fn install_agent_driver_from_registry( ); am.save_state(&local_state)?; am.stop_daemon_by_key(db_type).await; + cleanup_driver_download_cache_after_success(am, db_type); progress(AgentProgressEvent::step("done")); Ok(()) } @@ -986,27 +993,52 @@ fn prune_download_cache(am: &AgentManager) -> Result<(), String> { } fn prune_driver_download_cache(am: &AgentManager, db_type: &str) -> Result<(), String> { + let prefix = format!("driver-{}-", cache_file_token(db_type)); + remove_download_cache_entries(am, |name| name.starts_with(&prefix), "cached driver download") +} + +fn prune_jre_download_cache(am: &AgentManager, jre_key: &str) -> Result<(), String> { + let prefix = format!("jre-{}-", cache_file_token(jre_key)); + remove_download_cache_entries(am, |name| name.starts_with(&prefix), "cached JRE download") +} + +fn cleanup_driver_download_cache_after_success(am: &AgentManager, db_type: &str) { + if let Err(err) = prune_driver_download_cache(am, db_type) { + log::warn!("Failed to clean cached download for {db_type}: {err}"); + } +} + +fn cleanup_jre_download_cache_after_success(am: &AgentManager, jre_key: &str) { + if let Err(err) = prune_jre_download_cache(am, jre_key) { + log::warn!("Failed to clean cached JRE download for {jre_key}: {err}"); + } +} + +fn remove_download_cache_entries( + am: &AgentManager, + should_remove: impl Fn(&str) -> bool, + context: &str, +) -> Result<(), String> { let cache_dir = am.download_cache_dir(); let Ok(entries) = std::fs::read_dir(&cache_dir) else { return Ok(()); }; - let prefix = format!("driver-{}-", cache_file_token(db_type)); for entry in entries.flatten() { let path = entry.path(); let Some(name) = path.file_name().and_then(|value| value.to_str()) else { continue; }; - if name.starts_with(&prefix) { - let meta = match entry.metadata() { - Ok(meta) => meta, - Err(_) => continue, - }; - if meta.is_dir() { - std::fs::remove_dir_all(&path) - .map_err(|err| format!("Failed to remove cached driver download: {err}"))?; - } else { - std::fs::remove_file(&path).map_err(|err| format!("Failed to remove cached driver download: {err}"))?; - } + if !should_remove(name) { + continue; + } + let meta = match entry.metadata() { + Ok(meta) => meta, + Err(_) => continue, + }; + if meta.is_dir() { + std::fs::remove_dir_all(&path).map_err(|err| format!("Failed to remove {context}: {err}"))?; + } else { + std::fs::remove_file(&path).map_err(|err| format!("Failed to remove {context}: {err}"))?; } } Ok(()) @@ -1395,11 +1427,12 @@ mod agent_registry_install_tests { url: &str, dest: &Path, bytes: &[u8], - ) { + ) -> PathBuf { let cache_path = cached_download_path(am, url, bytes.len() as u64, Some(CacheIdentity::Driver { db_type, version }), dest); std::fs::create_dir_all(cache_path.parent().unwrap()).unwrap(); - std::fs::write(cache_path, bytes).unwrap(); + std::fs::write(&cache_path, bytes).unwrap(); + cache_path } #[tokio::test] @@ -1411,12 +1444,14 @@ mod agent_registry_install_tests { let native_bytes = b"native-agent"; let registry = registry_with_native_and_legacy_jar(db_type, version, native_url, native_bytes.len() as u64); let native_path = manager.driver_native_path(db_type); - write_cached_driver_download(&manager, db_type, version, native_url, &native_path, native_bytes); + let cache_path = + write_cached_driver_download(&manager, db_type, version, native_url, &native_path, native_bytes); let progress = |_| {}; install_agent_driver_from_registry(&manager, ®istry, db_type, &progress, None, None).await.unwrap(); assert_eq!(std::fs::read(&native_path).unwrap(), native_bytes); + assert!(!cache_path.exists()); assert!(!manager.driver_jar_path(db_type).exists()); assert_eq!(manager.load_state().installed_drivers.get(db_type).unwrap().version, version); } @@ -1430,7 +1465,7 @@ mod agent_registry_install_tests { let jar_bytes = b"jar"; let registry = registry_with_jar(db_type, version, jar_url, jar_bytes.len() as u64); let jar_path = manager.driver_jar_path(db_type); - write_cached_driver_download(&manager, db_type, version, jar_url, &jar_path, jar_bytes); + let cache_path = write_cached_driver_download(&manager, db_type, version, jar_url, &jar_path, jar_bytes); manager .save_state(&crate::agent_manager::AgentState { java_runtime: JavaRuntimeConfig { mode: JavaRuntimeMode::System, custom_java_path: None }, @@ -1443,6 +1478,7 @@ mod agent_registry_install_tests { install_agent_driver_from_registry(&manager, ®istry, db_type, &progress, None, None).await.unwrap_err(); assert!(err.contains("invalid or corrupt")); + assert!(cache_path.exists()); assert!(!jar_path.exists()); assert!(!manager.load_state().installed_drivers.contains_key(db_type)); } diff --git a/crates/dbx-core/tests/agent_service.rs b/crates/dbx-core/tests/agent_service.rs index 0cfde0be58..dbec2fd1df 100644 --- a/crates/dbx-core/tests/agent_service.rs +++ b/crates/dbx-core/tests/agent_service.rs @@ -3,8 +3,9 @@ use dbx_core::agent_manager::{ JreInfo, DEFAULT_JRE_KEY, }; use dbx_core::agent_service::{ - build_agent_list, github_url_to_r2_path, import_agent_jar, import_agents_from_zip, is_app_version_compatible, - jre_needs_install, local_agent_jar_candidates, replace_download, uninstall_agent_driver, AgentProgressEvent, + build_agent_list, clear_agent_download_cache, github_url_to_r2_path, import_agent_jar, import_agents_from_zip, + is_app_version_compatible, jre_needs_install, local_agent_jar_candidates, replace_download, uninstall_agent_driver, + AgentProgressEvent, }; fn test_manager(name: &str) -> AgentManager { @@ -444,6 +445,31 @@ async fn uninstall_driver_removes_artifact_and_state() { assert!(!manager.load_state().installed_drivers.contains_key("h2")); } +#[test] +fn clear_download_cache_removes_only_cache_entries() { + let manager = test_manager("clear-download-cache"); + let cache_dir = manager.download_cache_dir(); + let driver_dir = manager.driver_dir("h2"); + std::fs::create_dir_all(&cache_dir).unwrap(); + std::fs::create_dir_all(&driver_dir).unwrap(); + let driver_cache = cache_dir.join("driver-h2-0.1.0-abc-agent.jar"); + let jre_cache = cache_dir.join("jre-21-21.0.11-abc-jre-download.tar.gz"); + let nested_cache = cache_dir.join("stale-dir"); + let installed_driver = driver_dir.join("agent.jar"); + std::fs::write(&driver_cache, b"h2").unwrap(); + std::fs::write(&jre_cache, b"jre").unwrap(); + std::fs::create_dir_all(&nested_cache).unwrap(); + std::fs::write(nested_cache.join("artifact"), b"x").unwrap(); + std::fs::write(&installed_driver, b"driver").unwrap(); + + clear_agent_download_cache(&manager).unwrap(); + + assert!(!driver_cache.exists()); + assert!(!jre_cache.exists()); + assert!(!nested_cache.exists()); + assert!(installed_driver.exists()); +} + #[test] fn offline_zip_import_emits_progress_and_updates_state() { let manager = test_manager("offline-progress"); diff --git a/crates/dbx-web/src/main.rs b/crates/dbx-web/src/main.rs index 34711c9bae..9e0c1cd564 100644 --- a/crates/dbx-web/src/main.rs +++ b/crates/dbx-web/src/main.rs @@ -251,6 +251,7 @@ async fn main() { .route("/agents/installed-local", get(routes::agents::list_installed_agents_local)) .route("/agents/installed", get(routes::agents::list_installed_agents)) .route("/agents/storage-usage", get(routes::agents::get_driver_store_usage)) + .route("/agents/download-cache", delete(routes::agents::clear_driver_download_cache)) .route("/agents/runtime", get(routes::agents::get_driver_runtime_summary)) .route("/agents/runtime/stop", post(routes::agents::stop_driver_runtime)) .route("/agents/runtime/restart", post(routes::agents::restart_driver_runtime)) diff --git a/crates/dbx-web/src/routes/agents.rs b/crates/dbx-web/src/routes/agents.rs index 606f27c5c8..e9b9493f2a 100644 --- a/crates/dbx-web/src/routes/agents.rs +++ b/crates/dbx-web/src/routes/agents.rs @@ -7,9 +7,9 @@ use dbx_core::agent_manager::{ AgentDriverInfo, AgentState, DriverStoreUsage, JavaRuntimeConfig, JavaRuntimeMode, DEFAULT_JRE_KEY, }; use dbx_core::agent_service::{ - build_agent_list, fetch_registry, import_agents_from_zip as import_agents_from_zip_core, install_agent_driver, - invalidate_registry_cache, reinstall_agent_jre, uninstall_agent_driver, uninstall_agent_jre, - upgrade_all_agent_drivers, AgentProgressEvent, + build_agent_list, clear_agent_download_cache, fetch_registry, + import_agents_from_zip as import_agents_from_zip_core, install_agent_driver, invalidate_registry_cache, + reinstall_agent_jre, uninstall_agent_driver, uninstall_agent_jre, upgrade_all_agent_drivers, AgentProgressEvent, }; use dbx_core::driver_runtime::DriverRuntimeSummary; use futures::Stream; @@ -53,6 +53,13 @@ pub async fn get_driver_store_usage(State(state): State>) -> Resul Ok(Json(state.app.agent_manager.collect_driver_store_usage(state.app.plugins.root_dir()))) } +pub async fn clear_driver_download_cache( + State(state): State>, +) -> Result, AppError> { + clear_agent_download_cache(&state.app.agent_manager).map_err(AppError)?; + Ok(Json(serde_json::json!({ "ok": true }))) +} + pub async fn get_driver_runtime_summary( State(state): State>, ) -> Result, AppError> { diff --git a/src-tauri/src/commands/agents.rs b/src-tauri/src/commands/agents.rs index dc7b94fc49..9890bbfbce 100644 --- a/src-tauri/src/commands/agents.rs +++ b/src-tauri/src/commands/agents.rs @@ -4,9 +4,10 @@ use tauri::{Emitter, State}; use dbx_core::agent_manager::{AgentDriverInfo, DriverStoreUsage, JavaRuntimeConfig, JavaRuntimeMode, DEFAULT_JRE_KEY}; use dbx_core::agent_service::{ - build_agent_list, fetch_registry, import_agent_jar, import_agents_from_zip as import_agents_from_zip_core, - install_agent_driver, invalidate_registry_cache, reinstall_agent_jre, uninstall_agent_driver, uninstall_agent_jre, - upgrade_all_agent_drivers, AgentProgressEvent, UpgradeAllAgentDriversResult, + build_agent_list, clear_agent_download_cache, fetch_registry, import_agent_jar, + import_agents_from_zip as import_agents_from_zip_core, install_agent_driver, invalidate_registry_cache, + reinstall_agent_jre, uninstall_agent_driver, uninstall_agent_jre, upgrade_all_agent_drivers, AgentProgressEvent, + UpgradeAllAgentDriversResult, }; use dbx_core::connection::AppState; use dbx_core::driver_runtime::DriverRuntimeSummary; @@ -33,6 +34,11 @@ pub async fn get_driver_store_usage(state: State<'_, Arc>) -> Result>) -> Result<(), String> { + clear_agent_download_cache(&state.agent_manager) +} + #[tauri::command] pub async fn get_driver_runtime_summary(state: State<'_, Arc>) -> Result { Ok(dbx_core::driver_runtime::collect_driver_runtime_summary(state.inner().as_ref()).await) diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index e9e3161155..c496e6c1ac 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -1121,6 +1121,7 @@ pub fn run() { commands::agents::list_installed_agents, commands::agents::list_installed_agents_local, commands::agents::get_driver_store_usage, + commands::agents::clear_driver_download_cache, commands::agents::get_driver_runtime_summary, commands::agents::stop_driver_runtime, commands::agents::restart_driver_runtime,