Add api to manage sorting presets
Signed-off-by: trivernis <trivernis@protonmail.com>pull/12/head
parent
78a5780ff1
commit
d22c7499f7
@ -1,52 +1,52 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "mediarepo-api"
|
name = "mediarepo-api"
|
||||||
version = "0.28.0"
|
version = "0.28.1"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
license = "gpl-3"
|
license = "gpl-3"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tracing = "^0.1.29"
|
tracing = "0.1.30"
|
||||||
thiserror = "^1.0.30"
|
thiserror = "1.0.30"
|
||||||
async-trait = {version = "^0.1.52", optional=true}
|
async-trait = { version = "0.1.52", optional = true }
|
||||||
parking_lot = {version="^0.11.2", optional=true}
|
parking_lot = { version = "0.12.0", optional = true }
|
||||||
serde_json = {version="^1.0.73", optional=true}
|
serde_json = { version = "1.0.78", optional = true }
|
||||||
directories = {version="^4.0.1", optional=true}
|
directories = { version = "4.0.1", optional = true }
|
||||||
mime_guess = {version = "^2.0.3", optional=true}
|
mime_guess = { version = "2.0.3", optional = true }
|
||||||
serde_piecewise_default = "^0.2.0"
|
serde_piecewise_default = "0.2.0"
|
||||||
futures = {version = "^0.3.19", optional=true}
|
futures = { version = "0.3.19", optional = true }
|
||||||
url = {version = "^2.2.2", optional=true }
|
url = { version = "2.2.2", optional = true }
|
||||||
pathsearch = {version="^0.2.0", optional=true}
|
pathsearch = { version = "0.2.0", optional = true }
|
||||||
|
|
||||||
[dependencies.bromine]
|
[dependencies.bromine]
|
||||||
version = "^0.17.1"
|
version = "0.17.1"
|
||||||
optional = true
|
optional = true
|
||||||
features = ["serialize_bincode"]
|
features = ["serialize_bincode"]
|
||||||
|
|
||||||
[dependencies.serde]
|
[dependencies.serde]
|
||||||
version = "^1.0.132"
|
version = "1.0.136"
|
||||||
features = ["serde_derive"]
|
features = ["serde_derive"]
|
||||||
|
|
||||||
[dependencies.chrono]
|
[dependencies.chrono]
|
||||||
version = "^0.4.19"
|
version = "0.4.19"
|
||||||
features = ["serde"]
|
features = ["serde"]
|
||||||
|
|
||||||
[dependencies.tauri]
|
[dependencies.tauri]
|
||||||
version = "^1.0.0-beta.8"
|
version = "1.0.0-beta.8"
|
||||||
optional=true
|
optional=true
|
||||||
default-features = false
|
default-features = false
|
||||||
features = []
|
features = []
|
||||||
|
|
||||||
[dependencies.tokio]
|
[dependencies.tokio]
|
||||||
version = "^1.15.0"
|
version = "1.16.1"
|
||||||
optional = true
|
optional = true
|
||||||
features = ["sync", "fs", "net", "io-util", "io-std", "time", "rt", "process"]
|
features = ["sync", "fs", "net", "io-util", "io-std", "time", "rt", "process"]
|
||||||
|
|
||||||
[dependencies.toml]
|
[dependencies.toml]
|
||||||
version = "^0.5.8"
|
version = "0.5.8"
|
||||||
optional = true
|
optional = true
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
tauri-plugin = ["client-api","tauri", "parking_lot", "serde_json", "tokio", "toml", "directories", "mime_guess", "futures", "url"]
|
tauri-plugin = ["client-api","tauri", "parking_lot", "serde_json", "tokio", "toml", "directories", "mime_guess", "futures", "url"]
|
||||||
client-api = ["bromine", "async-trait", "tokio", "pathsearch"]
|
client-api = ["bromine", "async-trait", "tokio", "pathsearch"]
|
||||||
|
@ -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<Context> {
|
||||||
|
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<Vec<SortingPreset>> {
|
||||||
|
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<SortKey>) -> ApiResult<SortingPreset> {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
@ -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<Vec<SortingPreset>> {
|
||||||
|
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<SortKey>) -> PluginResult<SortingPreset> {
|
||||||
|
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(())
|
||||||
|
}
|
Loading…
Reference in New Issue