Allow for excluding certain tags from a file search

This commit is contained in:
Cameron
2024-11-23 20:21:19 -05:00
parent 6986540295
commit 9a32a1cfe7
3 changed files with 23 additions and 7 deletions

View File

@@ -24,7 +24,7 @@ use crate::tags::TagDao;
use crate::video::StreamActor;
use path_absolutize::*;
use rand::prelude::SliceRandom;
use rand::{random, thread_rng};
use rand::{thread_rng};
use serde::Deserialize;
pub async fn list_photos<TagD: TagDao, FS: FileSystemAccess>(
@@ -39,7 +39,7 @@ pub async fn list_photos<TagD: TagDao, FS: FileSystemAccess>(
let search_recursively = req.recursive.unwrap_or(false);
if let Some(tag_ids) = &req.tag_ids {
if search_recursively {
let filter_mode = req.tag_filter_mode.unwrap_or(FilterMode::Any);
let filter_mode = &req.tag_filter_mode.unwrap_or(FilterMode::Any);
debug!(
"Searching for tags: {}. With path: '{}' and filter mode: {:?}",
tag_ids, search_path, filter_mode
@@ -51,10 +51,16 @@ pub async fn list_photos<TagD: TagDao, FS: FileSystemAccess>(
.filter_map(|t| t.parse().ok())
.collect::<Vec<i32>>();
let exclude_tag_ids = req.exclude_tag_ids.clone()
.unwrap_or(String::new())
.split(',')
.filter_map(|t| t.parse().ok())
.collect::<Vec<i32>>();
return dao
.get_files_with_any_tag_ids(tag_ids.clone())
.get_files_with_any_tag_ids(tag_ids.clone(), exclude_tag_ids.clone())
.context(format!("Failed to get files with tag_ids: {:?}", tag_ids))
.map(|mut tagged_files| {
.map(|tagged_files| {
return if let Some(sort_type) = req.sort {
debug!("Sorting files: {:?}", sort_type);
sort(tagged_files, sort_type)