From d8560a180c9e35bf846b5ea8ec8cc7abb8113e6c Mon Sep 17 00:00:00 2001 From: Trivernis Date: Mon, 27 Dec 2021 16:58:27 +0100 Subject: [PATCH] Add api to get repository metadata Signed-off-by: Trivernis --- mediarepo-api/src/client_api/repo.rs | 15 ++++++++++++--- mediarepo-api/src/tauri_plugin/commands/repo.rs | 10 +++++++++- mediarepo-api/src/tauri_plugin/mod.rs | 3 ++- mediarepo-api/src/types/repo.rs | 12 ++++++++++++ 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/mediarepo-api/src/client_api/repo.rs b/mediarepo-api/src/client_api/repo.rs index 45e234f..6abd233 100644 --- a/mediarepo-api/src/client_api/repo.rs +++ b/mediarepo-api/src/client_api/repo.rs @@ -1,9 +1,10 @@ -use crate::client_api::error::ApiResult; -use crate::client_api::IPCApi; -use crate::types::repo::FrontendState; use bromine::prelude::*; use tokio::time::Duration; +use crate::client_api::error::ApiResult; +use crate::client_api::IPCApi; +use crate::types::repo::{FrontendState, RepositoryMetadata}; + #[derive(Clone)] pub struct RepoApi { ctx: PooledContext, @@ -24,6 +25,14 @@ impl RepoApi { Self { ctx } } + /// Returns metadata about the repository + #[tracing::instrument(level = "debug", skip(self))] + pub async fn get_repo_metadata(&self) -> ApiResult { + let metadata = self.emit_and_get("repository_metadata", (), Some(Duration::from_secs(2))).await?; + + Ok(metadata) + } + /// Returns the state of the frontend that is stored in the repo #[tracing::instrument(level = "debug", skip(self))] pub async fn get_frontend_state(&self) -> ApiResult { diff --git a/mediarepo-api/src/tauri_plugin/commands/repo.rs b/mediarepo-api/src/tauri_plugin/commands/repo.rs index 1912de4..3545b64 100644 --- a/mediarepo-api/src/tauri_plugin/commands/repo.rs +++ b/mediarepo-api/src/tauri_plugin/commands/repo.rs @@ -3,7 +3,7 @@ use crate::client_api::ApiClient; use crate::tauri_plugin::commands::{ApiAccess, AppAccess, BufferAccess}; use crate::tauri_plugin::error::{PluginError, PluginResult}; use crate::tauri_plugin::settings::{save_settings, Repository}; -use crate::types::repo::FrontendState; +use crate::types::repo::{FrontendState, RepositoryMetadata}; use serde::{Deserialize, Serialize}; use std::mem; use std::path::PathBuf; @@ -190,6 +190,14 @@ pub async fn select_repository( Ok(()) } +#[tauri::command] +pub async fn get_repo_metadata(api_state: ApiAccess<'_>) -> PluginResult { + let api = api_state.api().await?; + let metadata = api.repo.get_repo_metadata().await?; + + Ok(metadata) +} + #[tauri::command] pub async fn get_frontend_state(api_state: ApiAccess<'_>) -> PluginResult> { let api = api_state.api().await?; diff --git a/mediarepo-api/src/tauri_plugin/mod.rs b/mediarepo-api/src/tauri_plugin/mod.rs index 574408e..4f012fc 100644 --- a/mediarepo-api/src/tauri_plugin/mod.rs +++ b/mediarepo-api/src/tauri_plugin/mod.rs @@ -63,7 +63,8 @@ impl MediarepoPlugin { get_frontend_state, set_frontend_state, get_all_namespaces, - get_files + get_files, + get_repo_metadata ]), } } diff --git a/mediarepo-api/src/types/repo.rs b/mediarepo-api/src/types/repo.rs index 9a7139f..c17c751 100644 --- a/mediarepo-api/src/types/repo.rs +++ b/mediarepo-api/src/types/repo.rs @@ -4,3 +4,15 @@ use serde::{Deserialize, Serialize}; pub struct FrontendState { pub state: Option, } + +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct RepositoryMetadata { + pub version: String, + pub file_count: u64, + pub tag_count: u64, + pub namespace_count: u64, + pub total_size: u64, + pub image_size: u64, + pub database_size: u64, + pub thumbnail_size: u64, +} \ No newline at end of file