Use PhotoSize enum in file requests

This commit is contained in:
Cameron Cordes
2024-06-30 17:49:55 -04:00
parent a403903807
commit 9a486b3f66
2 changed files with 21 additions and 12 deletions

View File

@@ -103,7 +103,8 @@ pub struct PhotosResponse {
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct FilesRequest { pub struct FilesRequest {
pub path: String, pub path: String,
pub tag_ids: Option<String>, // comma separated numbers // comma separated numbers
pub tag_ids: Option<String>,
pub tag_filter_mode: Option<FilterMode>, pub tag_filter_mode: Option<FilterMode>,
pub recursive: Option<bool>, pub recursive: Option<bool>,
} }
@@ -114,10 +115,17 @@ pub enum FilterMode {
All, All,
} }
#[derive(Copy, Clone, Deserialize, PartialEq, Debug)]
#[serde(rename_all = "lowercase")]
pub enum PhotoSize {
Full,
Thumb,
}
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct ThumbnailRequest { pub struct ThumbnailRequest {
pub path: String, pub path: String,
pub size: Option<String>, pub size: Option<PhotoSize>,
} }
#[derive(Deserialize)] #[derive(Deserialize)]

View File

@@ -80,7 +80,8 @@ async fn get_image(
app_state: Data<AppState>, app_state: Data<AppState>,
) -> impl Responder { ) -> impl Responder {
if let Some(path) = is_valid_full_path(&app_state.base_path, &req.path, false) { if let Some(path) = is_valid_full_path(&app_state.base_path, &req.path, false) {
if req.size.is_some() { let image_size = req.size.unwrap_or(PhotoSize::Full);
if image_size == PhotoSize::Thumb {
let relative_path = path let relative_path = path
.strip_prefix(&app_state.base_path) .strip_prefix(&app_state.base_path)
.expect("Error stripping base path prefix from thumbnail"); .expect("Error stripping base path prefix from thumbnail");