From a5403588cd612cc4f114960ff6ce7da2c26bc472 Mon Sep 17 00:00:00 2001 From: trivernis Date: Thu, 18 Nov 2021 19:06:59 +0100 Subject: [PATCH] Change find file filter to support or-expressions Signed-off-by: trivernis --- mediarepo-api/Cargo.toml | 2 +- mediarepo-api/src/client_api/file.rs | 10 +++++----- mediarepo-api/src/tauri_plugin/commands/file.rs | 6 +++--- mediarepo-api/src/types/files.rs | 13 ++++++++++--- mediarepo-api/src/types/misc.rs | 11 ++++++++--- 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/mediarepo-api/Cargo.toml b/mediarepo-api/Cargo.toml index 755fafd..32ecb6f 100644 --- a/mediarepo-api/Cargo.toml +++ b/mediarepo-api/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mediarepo-api" -version = "0.10.0" +version = "0.11.0" edition = "2018" license = "gpl-3" diff --git a/mediarepo-api/src/client_api/file.rs b/mediarepo-api/src/client_api/file.rs index dba44f3..a4e0cc6 100644 --- a/mediarepo-api/src/client_api/file.rs +++ b/mediarepo-api/src/client_api/file.rs @@ -1,8 +1,8 @@ use crate::client_api::error::ApiResult; use crate::client_api::IPCApi; use crate::types::files::{ - AddFileRequestHeader, FileMetadataResponse, FileOSMetadata, FindFilesByTagsRequest, - GetFileThumbnailOfSizeRequest, GetFileThumbnailsRequest, ReadFileRequest, SortKey, TagQuery, + AddFileRequestHeader, FileMetadataResponse, FileOSMetadata, FilterExpression, FindFilesRequest, + GetFileThumbnailOfSizeRequest, GetFileThumbnailsRequest, ReadFileRequest, SortKey, ThumbnailMetadataResponse, UpdateFileNameRequest, }; use crate::types::identifier::FileIdentifier; @@ -64,13 +64,13 @@ where #[tracing::instrument(level = "debug", skip(self))] pub async fn find_files( &self, - tags: Vec, + filters: Vec, sort_expression: Vec, ) -> ApiResult> { self.emit_and_get( "find_files", - FindFilesByTagsRequest { - tags, + FindFilesRequest { + filters, sort_expression, }, ) diff --git a/mediarepo-api/src/tauri_plugin/commands/file.rs b/mediarepo-api/src/tauri_plugin/commands/file.rs index ab829e0..822510d 100644 --- a/mediarepo-api/src/tauri_plugin/commands/file.rs +++ b/mediarepo-api/src/tauri_plugin/commands/file.rs @@ -2,7 +2,7 @@ use crate::tauri_plugin::commands::ApiAccess; use crate::tauri_plugin::error::PluginResult; use crate::tauri_plugin::utils::system_time_to_naive_date_time; use crate::types::files::{ - FileMetadataResponse, FileOSMetadata, SortKey, TagQuery, ThumbnailMetadataResponse, + FileMetadataResponse, FileOSMetadata, FilterExpression, SortKey, ThumbnailMetadataResponse, }; use crate::types::identifier::FileIdentifier; use serde::{Deserialize, Serialize}; @@ -63,12 +63,12 @@ pub async fn add_local_file( #[tauri::command] pub async fn find_files( - tags: Vec, + filters: Vec, sort_by: Vec, api_state: ApiAccess<'_>, ) -> PluginResult> { let api = api_state.api().await?; - let files = api.file.find_files(tags, sort_by).await?; + let files = api.file.find_files(filters, sort_by).await?; Ok(files) } diff --git a/mediarepo-api/src/types/files.rs b/mediarepo-api/src/types/files.rs index f1ac76e..cf68886 100644 --- a/mediarepo-api/src/types/files.rs +++ b/mediarepo-api/src/types/files.rs @@ -30,15 +30,22 @@ pub struct GetFilesTagsRequest { } #[derive(Clone, Debug, Serialize, Deserialize)] -pub struct FindFilesByTagsRequest { - pub tags: Vec, +pub struct FindFilesRequest { + pub filters: Vec, pub sort_expression: Vec, } +#[derive(Clone, Debug, Serialize, Deserialize)] +#[serde(tag = "filter_type")] +pub enum FilterExpression { + OrExpression(Vec), + Query(TagQuery), +} + #[derive(Clone, Debug, Serialize, Deserialize)] pub struct TagQuery { pub negate: bool, - pub name: String, + pub tags: String, } #[derive(Clone, Debug, Serialize, Deserialize)] diff --git a/mediarepo-api/src/types/misc.rs b/mediarepo-api/src/types/misc.rs index 73ca70d..cf04ed8 100644 --- a/mediarepo-api/src/types/misc.rs +++ b/mediarepo-api/src/types/misc.rs @@ -49,7 +49,12 @@ pub fn check_apis_compatible( client_version: (u32, u32, u32), server_version: (u32, u32, u32), ) -> bool { - // the major version must be the same while the client minor version can be lower than the servers - // so that the client has access to all its supported functionality - client_version.0 == server_version.0 && client_version.1 <= server_version.1 + if client_version.0 == 0 { + // For the beta and alpha (major 0) compare the minor and patch level + client_version.1 == server_version.1 && client_version.2 <= server_version.2 + } else { + // the major version must be the same while the client minor version can be lower than the servers + // so that the client has access to all its supported functionality + client_version.0 == server_version.0 && client_version.1 <= server_version.1 + } }