Add the ability to query files by tags independent of file path
This commit is contained in:
29
src/files.rs
29
src/files.rs
@@ -16,6 +16,7 @@ use log::{debug, error};
|
||||
use crate::data::{Claims, FilesRequest, FilterMode, PhotosResponse};
|
||||
use crate::AppState;
|
||||
|
||||
use crate::error::IntoHttpError;
|
||||
use crate::tags::TagDao;
|
||||
use path_absolutize::*;
|
||||
|
||||
@@ -28,6 +29,34 @@ pub async fn list_photos<TagD: TagDao, FS: FileSystemAccess>(
|
||||
) -> HttpResponse {
|
||||
let path = &req.path;
|
||||
|
||||
if let (Some(tag_ids), Some(filter_mode)) = (&req.tag_ids, &req.tag_filter_mode) {
|
||||
if *filter_mode == FilterMode::All {
|
||||
let mut dao = tag_dao.lock().expect("Unable to get TagDao");
|
||||
let tag_ids = tag_ids
|
||||
.split(',')
|
||||
.filter_map(|t| t.parse().ok())
|
||||
.collect::<Vec<i32>>();
|
||||
|
||||
return dao
|
||||
.get_files_with_tag_ids(tag_ids.clone())
|
||||
.map(|tagged_file| {
|
||||
tagged_file
|
||||
.iter()
|
||||
.map(|photo_name| photo_name.clone())
|
||||
.collect()
|
||||
})
|
||||
.context(format!("Failed to files with tag_ids: {:?}", tag_ids))
|
||||
.map(|tagged_files| {
|
||||
HttpResponse::Ok().json(PhotosResponse {
|
||||
photos: tagged_files,
|
||||
dirs: vec![],
|
||||
})
|
||||
})
|
||||
.into_http_internal_err()
|
||||
.unwrap_or_else(|e| e.error_response());
|
||||
}
|
||||
}
|
||||
|
||||
if let Ok(files) = file_system.get_files_for_path(path) {
|
||||
debug!("Valid path: {:?}", path);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user