Merge pull request 'Fix recursive searching with tags' (#27) from feature/fix-recursive-tag-search into master

Reviewed-on: #27
This commit was merged in pull request #27.
This commit is contained in:
2024-03-11 00:46:55 +00:00

View File

@@ -32,7 +32,7 @@ pub async fn list_photos<TagD: TagDao, FS: FileSystemAccess>(
file_system: web::Data<FS>,
tag_dao: web::Data<Mutex<TagD>>,
) -> HttpResponse {
let path = &req.path;
let search_path = &req.path;
let search_recursively = req.recursive.unwrap_or(false);
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);
debug!(
"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");
@@ -53,10 +53,18 @@ pub async fn list_photos<TagD: TagDao, FS: FileSystemAccess>(
.get_files_with_any_tag_ids(tag_ids.clone())
.context(format!("Failed to get files with tag_ids: {:?}", tag_ids))
.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
.iter()
.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();
tag_ids
.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) {
debug!("Valid search path: {:?}", path);
if let Ok(files) = file_system.get_files_for_path(search_path) {
debug!("Valid search path: {:?}", search_path);
let photos = files
.iter()