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 ]), } }