Add basic recursive tag searching support based on the search path

This commit is contained in:
Cameron Cordes
2024-03-07 17:56:50 -05:00
parent d58e34c18f
commit ef39359862
2 changed files with 16 additions and 2 deletions

View File

@@ -35,7 +35,9 @@ pub async fn list_photos<TagD: TagDao, FS: FileSystemAccess>(
) -> HttpResponse {
let path = &req.path;
// Do we need this?
if let (Some(tag_ids), Some(filter_mode)) = (&req.tag_ids, &req.tag_filter_mode) {
let search_recursively = &req.recursive.unwrap_or(false);
if *filter_mode == FilterMode::All {
let mut dao = tag_dao.lock().expect("Unable to get TagDao");
let tag_ids = tag_ids
@@ -45,10 +47,15 @@ pub async fn list_photos<TagD: TagDao, FS: FileSystemAccess>(
return dao
.get_files_with_tag_ids(tag_ids.clone())
.context(format!("Failed to files with tag_ids: {:?}", tag_ids))
.context(format!("Failed to get files with tag_ids: {:?}", tag_ids))
.map(|tagged_files| {
HttpResponse::Ok().json(PhotosResponse {
photos: tagged_files,
photos: tagged_files.iter().filter(|&file_path| {
let slash_count = file_path.split('/').count();
let search_path_slash_count = path.split('/').count();
slash_count > search_path_slash_count
}).map(|p| p.clone()).collect::<Vec<String>>(),
dirs: vec![],
})
})
@@ -77,6 +84,12 @@ pub async fn list_photos<TagD: TagDao, FS: FileSystemAccess>(
})
.map(|f| f.to_str().unwrap().to_string())
.filter(|file_path| {
let recursive = req.recursive.unwrap_or(false);
let file_slash_count = file_path.split("/").collect::<Vec<&str>>().len();
let filter_path_slash_count = path.split("/").collect::<Vec<&str>>().len();
// Skip if this path is below/deeper than the search path
if !recursive && file_slash_count > filter_path_slash_count { return false; }
if let (Some(tag_ids), Ok(mut tag_dao)) = (&req.tag_ids, tag_dao.lock()) {
let tag_ids = tag_ids
.split(',')