Add api to get repository metadata

Signed-off-by: Trivernis <trivernis@protonmail.com>
pull/4/head
Trivernis 3 years ago
parent 60140fcd97
commit d8560a180c

@ -1,9 +1,10 @@
use crate::client_api::error::ApiResult;
use crate::client_api::IPCApi;
use crate::types::repo::FrontendState;
use bromine::prelude::*; use bromine::prelude::*;
use tokio::time::Duration; use tokio::time::Duration;
use crate::client_api::error::ApiResult;
use crate::client_api::IPCApi;
use crate::types::repo::{FrontendState, RepositoryMetadata};
#[derive(Clone)] #[derive(Clone)]
pub struct RepoApi { pub struct RepoApi {
ctx: PooledContext, ctx: PooledContext,
@ -24,6 +25,14 @@ impl RepoApi {
Self { ctx } Self { ctx }
} }
/// Returns metadata about the repository
#[tracing::instrument(level = "debug", skip(self))]
pub async fn get_repo_metadata(&self) -> ApiResult<RepositoryMetadata> {
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 /// Returns the state of the frontend that is stored in the repo
#[tracing::instrument(level = "debug", skip(self))] #[tracing::instrument(level = "debug", skip(self))]
pub async fn get_frontend_state(&self) -> ApiResult<FrontendState> { pub async fn get_frontend_state(&self) -> ApiResult<FrontendState> {

@ -3,7 +3,7 @@ use crate::client_api::ApiClient;
use crate::tauri_plugin::commands::{ApiAccess, AppAccess, BufferAccess}; use crate::tauri_plugin::commands::{ApiAccess, AppAccess, BufferAccess};
use crate::tauri_plugin::error::{PluginError, PluginResult}; use crate::tauri_plugin::error::{PluginError, PluginResult};
use crate::tauri_plugin::settings::{save_settings, Repository}; use crate::tauri_plugin::settings::{save_settings, Repository};
use crate::types::repo::FrontendState; use crate::types::repo::{FrontendState, RepositoryMetadata};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::mem; use std::mem;
use std::path::PathBuf; use std::path::PathBuf;
@ -190,6 +190,14 @@ pub async fn select_repository(
Ok(()) Ok(())
} }
#[tauri::command]
pub async fn get_repo_metadata(api_state: ApiAccess<'_>) -> PluginResult<RepositoryMetadata> {
let api = api_state.api().await?;
let metadata = api.repo.get_repo_metadata().await?;
Ok(metadata)
}
#[tauri::command] #[tauri::command]
pub async fn get_frontend_state(api_state: ApiAccess<'_>) -> PluginResult<Option<String>> { pub async fn get_frontend_state(api_state: ApiAccess<'_>) -> PluginResult<Option<String>> {
let api = api_state.api().await?; let api = api_state.api().await?;

@ -63,7 +63,8 @@ impl<R: Runtime> MediarepoPlugin<R> {
get_frontend_state, get_frontend_state,
set_frontend_state, set_frontend_state,
get_all_namespaces, get_all_namespaces,
get_files get_files,
get_repo_metadata
]), ]),
} }
} }

@ -4,3 +4,15 @@ use serde::{Deserialize, Serialize};
pub struct FrontendState { pub struct FrontendState {
pub state: Option<String>, pub state: Option<String>,
} }
#[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,
}
Loading…
Cancel
Save