Move size calculation to different api

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

@ -1,6 +1,6 @@
[package]
name = "mediarepo-api"
version = "0.18.0"
version = "0.19.0"
edition = "2018"
license = "gpl-3"

@ -3,7 +3,7 @@ use tokio::time::Duration;
use crate::client_api::error::ApiResult;
use crate::client_api::IPCApi;
use crate::types::repo::{FrontendState, RepositoryMetadata};
use crate::types::repo::{FrontendState, RepositoryMetadata, SizeMetadata, SizeType};
#[derive(Clone)]
pub struct RepoApi {
@ -28,17 +28,19 @@ impl RepoApi {
/// 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(30))).await?;
self.emit_and_get("repository_metadata", (), Some(Duration::from_secs(3))).await
}
Ok(metadata)
/// Returns the size of a given type
#[tracing::instrument(level = "debug", skip(self))]
pub async fn get_size(&self, size_type: SizeType) -> ApiResult<SizeMetadata> {
self.emit_and_get("size_metadata", (), Some(Duration::from_secs(30))).await
}
/// 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<FrontendState> {
let state = self.emit_and_get("frontend_state", (), Some(Duration::from_secs(5))).await?;
Ok(state)
self.emit_and_get("frontend_state", (), Some(Duration::from_secs(5))).await
}
/// Sets the state of the frontend

@ -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, RepositoryMetadata};
use crate::types::repo::{FrontendState, RepositoryMetadata, SizeMetadata, SizeType};
use serde::{Deserialize, Serialize};
use std::mem;
use std::path::PathBuf;
@ -198,6 +198,14 @@ pub async fn get_repo_metadata(api_state: ApiAccess<'_>) -> PluginResult<Reposit
Ok(metadata)
}
#[tauri::command]
pub async fn get_size(api_state: ApiAccess<'_>, size_type: SizeType) -> PluginResult<SizeMetadata> {
let api = api_state.api().await?;
let size = api.repo.get_size(size_type).await?;
Ok(size)
}
#[tauri::command]
pub async fn get_frontend_state(api_state: ApiAccess<'_>) -> PluginResult<Option<String>> {
let api = api_state.api().await?;

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

@ -13,8 +13,18 @@ pub struct RepositoryMetadata {
pub namespace_count: u64,
pub mapping_count: u64,
pub hash_count: u64,
pub total_size: u64,
pub file_size: u64,
pub database_size: u64,
pub thumbnail_size: u64,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct SizeMetadata {
pub size_type: SizeType,
pub size: u64,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub enum SizeType {
Total,
FileFolder,
ThumbFolder,
DatabaseFile,
}
Loading…
Cancel
Save