Fix recursive searching with tags

This commit is contained in:
Cameron Cordes
2024-03-10 20:45:18 -04:00
parent 3c9263eb48
commit 3925d835f6

View File

@@ -32,7 +32,7 @@ pub async fn list_photos<TagD: TagDao, FS: FileSystemAccess>(
file_system: web::Data<FS>, file_system: web::Data<FS>,
tag_dao: web::Data<Mutex<TagD>>, tag_dao: web::Data<Mutex<TagD>>,
) -> HttpResponse { ) -> HttpResponse {
let path = &req.path; let search_path = &req.path;
let search_recursively = req.recursive.unwrap_or(false); let search_recursively = req.recursive.unwrap_or(false);
if let Some(tag_ids) = &req.tag_ids { if let Some(tag_ids) = &req.tag_ids {
@@ -40,7 +40,7 @@ pub async fn list_photos<TagD: TagDao, FS: FileSystemAccess>(
let filter_mode = req.tag_filter_mode.unwrap_or(FilterMode::Any); let filter_mode = req.tag_filter_mode.unwrap_or(FilterMode::Any);
debug!( debug!(
"Searching for tags: {}. With path: '{}' and filter mode: {:?}", "Searching for tags: {}. With path: '{}' and filter mode: {:?}",
tag_ids, path, filter_mode tag_ids, search_path, filter_mode
); );
let mut dao = tag_dao.lock().expect("Unable to get TagDao"); let mut dao = tag_dao.lock().expect("Unable to get TagDao");
@@ -53,10 +53,18 @@ pub async fn list_photos<TagD: TagDao, FS: FileSystemAccess>(
.get_files_with_any_tag_ids(tag_ids.clone()) .get_files_with_any_tag_ids(tag_ids.clone())
.context(format!("Failed to get files with tag_ids: {:?}", tag_ids)) .context(format!("Failed to get files with tag_ids: {:?}", tag_ids))
.map(|tagged_files| match filter_mode { .map(|tagged_files| match filter_mode {
FilterMode::Any => tagged_files, FilterMode::Any => tagged_files
.iter()
.filter(|file| file.starts_with(search_path))
.cloned()
.collect(),
FilterMode::All => tagged_files FilterMode::All => tagged_files
.iter() .iter()
.filter(|&file_path| { .filter(|&file_path| {
if !file_path.starts_with(search_path) {
return false;
}
let file_tags = dao.get_tags_for_path(file_path).unwrap_or_default(); let file_tags = dao.get_tags_for_path(file_path).unwrap_or_default();
tag_ids tag_ids
.iter() .iter()
@@ -78,8 +86,8 @@ pub async fn list_photos<TagD: TagDao, FS: FileSystemAccess>(
} }
} }
if let Ok(files) = file_system.get_files_for_path(path) { if let Ok(files) = file_system.get_files_for_path(search_path) {
debug!("Valid search path: {:?}", path); debug!("Valid search path: {:?}", search_path);
let photos = files let photos = files
.iter() .iter()