diff --git a/mediarepo-api/Cargo.toml b/mediarepo-api/Cargo.toml index 5a8a80e..522a42f 100644 --- a/mediarepo-api/Cargo.toml +++ b/mediarepo-api/Cargo.toml @@ -1,52 +1,52 @@ [package] name = "mediarepo-api" -version = "0.28.0" +version = "0.28.1" edition = "2018" license = "gpl-3" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -tracing = "^0.1.29" -thiserror = "^1.0.30" -async-trait = {version = "^0.1.52", optional=true} -parking_lot = {version="^0.11.2", optional=true} -serde_json = {version="^1.0.73", optional=true} -directories = {version="^4.0.1", optional=true} -mime_guess = {version = "^2.0.3", optional=true} -serde_piecewise_default = "^0.2.0" -futures = {version = "^0.3.19", optional=true} -url = {version = "^2.2.2", optional=true } -pathsearch = {version="^0.2.0", optional=true} +tracing = "0.1.30" +thiserror = "1.0.30" +async-trait = { version = "0.1.52", optional = true } +parking_lot = { version = "0.12.0", optional = true } +serde_json = { version = "1.0.78", optional = true } +directories = { version = "4.0.1", optional = true } +mime_guess = { version = "2.0.3", optional = true } +serde_piecewise_default = "0.2.0" +futures = { version = "0.3.19", optional = true } +url = { version = "2.2.2", optional = true } +pathsearch = { version = "0.2.0", optional = true } [dependencies.bromine] -version = "^0.17.1" +version = "0.17.1" optional = true features = ["serialize_bincode"] [dependencies.serde] -version = "^1.0.132" +version = "1.0.136" features = ["serde_derive"] [dependencies.chrono] -version = "^0.4.19" +version = "0.4.19" features = ["serde"] [dependencies.tauri] -version = "^1.0.0-beta.8" +version = "1.0.0-beta.8" optional=true default-features = false features = [] [dependencies.tokio] -version = "^1.15.0" +version = "1.16.1" optional = true features = ["sync", "fs", "net", "io-util", "io-std", "time", "rt", "process"] [dependencies.toml] -version = "^0.5.8" +version = "0.5.8" optional = true [features] tauri-plugin = ["client-api","tauri", "parking_lot", "serde_json", "tokio", "toml", "directories", "mime_guess", "futures", "url"] -client-api = ["bromine", "async-trait", "tokio", "pathsearch"] \ No newline at end of file +client-api = ["bromine", "async-trait", "tokio", "pathsearch"] diff --git a/mediarepo-api/src/client_api/mod.rs b/mediarepo-api/src/client_api/mod.rs index c3fbf2f..3dfbcab 100644 --- a/mediarepo-api/src/client_api/mod.rs +++ b/mediarepo-api/src/client_api/mod.rs @@ -4,6 +4,7 @@ pub mod job; pub mod protocol; pub mod repo; pub mod tag; +pub mod preset; use crate::client_api::error::{ApiError, ApiResult}; use crate::client_api::file::FileApi; @@ -15,6 +16,7 @@ use async_trait::async_trait; use bromine::ipc::stream_emitter::EmitMetadata; use bromine::prelude::*; use tokio::time::Duration; +use crate::client_api::preset::PresetApi; #[async_trait] pub trait IPCApi { @@ -48,6 +50,7 @@ pub struct ApiClient { pub tag: TagApi, pub repo: RepoApi, pub job: JobApi, + pub preset: PresetApi, } impl Clone for ApiClient { @@ -58,6 +61,7 @@ impl Clone for ApiClient { tag: self.tag.clone(), repo: self.repo.clone(), job: self.job.clone(), + preset: self.preset.clone(), } } } @@ -70,6 +74,7 @@ impl ApiClient { tag: TagApi::new(ctx.clone()), repo: RepoApi::new(ctx.clone()), job: JobApi::new(ctx.clone()), + preset: PresetApi::new(ctx.clone()), ctx, } } diff --git a/mediarepo-api/src/client_api/preset.rs b/mediarepo-api/src/client_api/preset.rs new file mode 100644 index 0000000..f62e0fc --- /dev/null +++ b/mediarepo-api/src/client_api/preset.rs @@ -0,0 +1,54 @@ +use std::time::Duration; +use bromine::prelude::*; +use crate::client_api::error::ApiResult; +use crate::types::filtering::{SortingPreset, SortKey}; +use super::IPCApi; + +#[derive(Clone)] +pub struct PresetApi { + ctx: PooledContext, +} + +impl IPCApi for PresetApi { + fn namespace() -> &'static str { + "presets" + } + + fn ctx(&self) -> PoolGuard { + self.ctx.acquire() + } +} + +impl PresetApi { + pub fn new(ctx: PooledContext) -> Self { + Self { ctx } + } + + /// Returns all sorting presets of the repository + #[tracing::instrument(level = "debug", skip(self))] + pub async fn all_sorting_presets(&self) -> ApiResult> { + self.emit_and_get( + "sorting_presets", + (), + Some(Duration::from_secs(1)) + ) + .await + } + + /// Adds a new sorting preset with the given keys + #[tracing::instrument(level = "debug", skip(self))] + pub async fn add_sorting_preset(&self, keys: Vec) -> ApiResult { + self.emit_and_get( + "add_sorting_preset", + keys, + Some(Duration::from_secs(1)) + ) + .await + } + + /// Deletes a given sorting preset by id + #[tracing::instrument(level = "debug", skip(self))] + pub async fn delete_sorting_preset(&self, id: i32) -> ApiResult<()> { + self.emit_and_get("delete_sorting_preset", id, Some(Duration::from_secs(1))).await + } +} diff --git a/mediarepo-api/src/tauri_plugin/commands/mod.rs b/mediarepo-api/src/tauri_plugin/commands/mod.rs index bd6a259..c06b7c8 100644 --- a/mediarepo-api/src/tauri_plugin/commands/mod.rs +++ b/mediarepo-api/src/tauri_plugin/commands/mod.rs @@ -5,6 +5,7 @@ pub use file::*; pub use job::*; pub use repo::*; pub use tag::*; +pub use preset::*; use crate::tauri_plugin::state::{ApiState, AppState, BufferState}; @@ -13,6 +14,7 @@ pub mod file; pub mod job; pub mod repo; pub mod tag; +pub mod preset; pub type ApiAccess<'a> = State<'a, ApiState>; pub type AppAccess<'a> = State<'a, AppState>; diff --git a/mediarepo-api/src/tauri_plugin/commands/preset.rs b/mediarepo-api/src/tauri_plugin/commands/preset.rs new file mode 100644 index 0000000..8bdb206 --- /dev/null +++ b/mediarepo-api/src/tauri_plugin/commands/preset.rs @@ -0,0 +1,27 @@ +use crate::tauri_plugin::commands::ApiAccess; +use crate::tauri_plugin::error::PluginResult; +use crate::types::filtering::{SortingPreset, SortKey}; + +#[tauri::command] +pub async fn all_sorting_presets(api_state: ApiAccess<'_>) -> PluginResult> { + let api = api_state.api().await?; + let presets = api.preset.all_sorting_presets().await?; + + Ok(presets) +} + +#[tauri::command] +pub async fn add_sorting_preset(api_state: ApiAccess<'_>, sort_keys: Vec) -> PluginResult { + let api = api_state.api().await?; + let preset = api.preset.add_sorting_preset(sort_keys).await?; + + Ok(preset) +} + +#[tauri::command] +pub async fn delete_sorting_preset(api_state: ApiAccess<'_>, id: i32) -> PluginResult<()> { + let api = api_state.api().await?; + api.preset.delete_sorting_preset(id).await?; + + Ok(()) +} \ No newline at end of file diff --git a/mediarepo-api/src/tauri_plugin/mod.rs b/mediarepo-api/src/tauri_plugin/mod.rs index 37e11c6..7a570a7 100644 --- a/mediarepo-api/src/tauri_plugin/mod.rs +++ b/mediarepo-api/src/tauri_plugin/mod.rs @@ -70,7 +70,10 @@ impl MediarepoPlugin { run_job, update_file_status, delete_file, - get_file_tag_map + get_file_tag_map, + all_sorting_presets, + add_sorting_preset, + delete_sorting_preset ]), } } diff --git a/mediarepo-api/src/types/filtering.rs b/mediarepo-api/src/types/filtering.rs index 916db73..3ffca1e 100644 --- a/mediarepo-api/src/types/filtering.rs +++ b/mediarepo-api/src/types/filtering.rs @@ -71,3 +71,9 @@ pub enum SortDirection { } impl Eq for SortDirection {} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct SortingPreset { + pub id: i32, + pub keys: Vec, +} \ No newline at end of file