feature/tagging #16
@@ -103,7 +103,7 @@ pub struct PhotosResponse {
|
||||
#[derive(Deserialize)]
|
||||
pub struct FilesRequest {
|
||||
pub path: String,
|
||||
pub tag_ids: Option<Vec<i32>>,
|
||||
pub tag_ids: Option<String>, // comma separated numbers
|
||||
pub tag_filter_mode: Option<FilterMode>,
|
||||
}
|
||||
|
||||
|
||||
16
src/files.rs
16
src/files.rs
@@ -13,7 +13,7 @@ use actix_web::{
|
||||
};
|
||||
use log::{debug, error};
|
||||
|
||||
use crate::data::{Claims, FilesRequest, FilterMode, PhotosResponse, ThumbnailRequest};
|
||||
use crate::data::{Claims, FilesRequest, FilterMode, PhotosResponse};
|
||||
use crate::AppState;
|
||||
|
||||
use crate::tags::TagDao;
|
||||
@@ -46,14 +46,22 @@ pub async fn list_photos<TagD: TagDao>(
|
||||
relative.to_path_buf()
|
||||
})
|
||||
.map(|f| f.to_str().unwrap().to_string())
|
||||
.filter(|path| {
|
||||
.filter(|file_path| {
|
||||
if let (Some(tag_ids), Ok(mut tag_dao)) = (&req.tag_ids, tag_dao.lock()) {
|
||||
let tag_ids = tag_ids
|
||||
.split(',')
|
||||
.filter_map(|t| t.parse().ok())
|
||||
.collect::<Vec<i32>>();
|
||||
|
||||
let filter_mode = &req.tag_filter_mode.unwrap_or(FilterMode::Any);
|
||||
|
||||
let file_tags = tag_dao.get_tags_for_path(path).unwrap_or_default();
|
||||
let file_tags = tag_dao.get_tags_for_path(file_path).unwrap_or_default();
|
||||
|
||||
return match filter_mode {
|
||||
FilterMode::Any => file_tags.iter().any(|t| tag_ids.contains(&t.id)),
|
||||
FilterMode::All => file_tags.iter().all(|t| tag_ids.contains(&t.id)),
|
||||
FilterMode::All => tag_ids
|
||||
.iter()
|
||||
.all(|id| file_tags.iter().any(|tag| &tag.id == id)),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user