From 8218ae323583a05a2d47b14a39f96a1d18ff1b3a Mon Sep 17 00:00:00 2001 From: trivernis Date: Tue, 30 Nov 2021 19:31:22 +0100 Subject: [PATCH] Add command to delete local repositories TG-25 Signed-off-by: trivernis --- .../src/tauri_plugin/commands/repo.rs | 23 +++++++++++++++++++ mediarepo-api/src/tauri_plugin/mod.rs | 3 ++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/mediarepo-api/src/tauri_plugin/commands/repo.rs b/mediarepo-api/src/tauri_plugin/commands/repo.rs index 23dd053..b17f625 100644 --- a/mediarepo-api/src/tauri_plugin/commands/repo.rs +++ b/mediarepo-api/src/tauri_plugin/commands/repo.rs @@ -81,6 +81,29 @@ pub async fn remove_repository(app_state: AppAccess<'_>, name: String) -> Plugin } } +#[tauri::command] +pub async fn delete_repository(app_state: AppAccess<'_>, name: String) -> PluginResult<()> { + let settings = app_state.settings.read().await; + + if let Some(repository) = settings.repositories.get(&name) { + if let Some(path) = &repository.path { + fs::remove_dir_all(PathBuf::from(path)).await?; + + Ok(()) + } else { + Err(PluginError::from(format!( + "The repository '{}' is a remote repository", + name + ))) + } + } else { + Err(PluginError::from(format!( + "The repository '{}' does not exist.", + name + ))) + } +} + #[tauri::command] pub async fn check_local_repository_exists(path: String) -> PluginResult { let config_path = PathBuf::from(path).join(REPO_CONFIG_FILE); diff --git a/mediarepo-api/src/tauri_plugin/mod.rs b/mediarepo-api/src/tauri_plugin/mod.rs index c7b06b5..73110f7 100644 --- a/mediarepo-api/src/tauri_plugin/mod.rs +++ b/mediarepo-api/src/tauri_plugin/mod.rs @@ -57,7 +57,8 @@ impl MediarepoPlugin { add_local_file, save_file_locally, delete_thumbnails, - read_file + read_file, + delete_repository ]), } }