Change find file filter to support or-expressions

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

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

@ -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<TagQuery>,
filters: Vec<FilterExpression>,
sort_expression: Vec<SortKey>,
) -> ApiResult<Vec<FileMetadataResponse>> {
self.emit_and_get(
"find_files",
FindFilesByTagsRequest {
tags,
FindFilesRequest {
filters,
sort_expression,
},
)

@ -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<TagQuery>,
filters: Vec<FilterExpression>,
sort_by: Vec<SortKey>,
api_state: ApiAccess<'_>,
) -> PluginResult<Vec<FileMetadataResponse>> {
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)
}

@ -30,15 +30,22 @@ pub struct GetFilesTagsRequest {
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct FindFilesByTagsRequest {
pub tags: Vec<TagQuery>,
pub struct FindFilesRequest {
pub filters: Vec<FilterExpression>,
pub sort_expression: Vec<SortKey>,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(tag = "filter_type")]
pub enum FilterExpression {
OrExpression(Vec<TagQuery>),
Query(TagQuery),
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct TagQuery {
pub negate: bool,
pub name: String,
pub tags: String,
}
#[derive(Clone, Debug, Serialize, Deserialize)]

@ -49,7 +49,12 @@ pub fn check_apis_compatible(
client_version: (u32, u32, u32),
server_version: (u32, u32, u32),
) -> bool {
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
}
}

Loading…
Cancel
Save