From 9a486b3f66761fa644c16ac1d88eb4cff98dea86 Mon Sep 17 00:00:00 2001 From: Cameron Cordes Date: Sun, 30 Jun 2024 17:49:55 -0400 Subject: [PATCH] Use PhotoSize enum in file requests --- src/data/mod.rs | 12 ++++++++++-- src/main.rs | 21 +++++++++++---------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/data/mod.rs b/src/data/mod.rs index 65049ba..55e053a 100644 --- a/src/data/mod.rs +++ b/src/data/mod.rs @@ -103,7 +103,8 @@ pub struct PhotosResponse { #[derive(Deserialize)] pub struct FilesRequest { pub path: String, - pub tag_ids: Option, // comma separated numbers + // comma separated numbers + pub tag_ids: Option, pub tag_filter_mode: Option, pub recursive: Option, } @@ -114,10 +115,17 @@ pub enum FilterMode { All, } +#[derive(Copy, Clone, Deserialize, PartialEq, Debug)] +#[serde(rename_all = "lowercase")] +pub enum PhotoSize { + Full, + Thumb, +} + #[derive(Deserialize)] pub struct ThumbnailRequest { pub path: String, - pub size: Option, + pub size: Option, } #[derive(Deserialize)] diff --git a/src/main.rs b/src/main.rs index 4c35123..83106c3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -80,7 +80,8 @@ async fn get_image( app_state: Data, ) -> impl Responder { 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 .strip_prefix(&app_state.base_path) .expect("Error stripping base path prefix from thumbnail"); @@ -279,7 +280,7 @@ async fn favorites( .expect("Unable to get FavoritesDao") .get_favorites(claims.sub.parse::().unwrap()) }) - .await + .await { Ok(Ok(favorites)) => { let favorites = favorites @@ -314,7 +315,7 @@ async fn put_add_favorite( .expect("Unable to get FavoritesDao") .add_favorite(user_id, &path) }) - .await + .await { Ok(Err(e)) if e.kind == DbErrorKind::AlreadyExists => { debug!("Favorite: {} exists for user: {}", &body.path, user_id); @@ -353,8 +354,8 @@ async fn delete_favorite( .expect("Unable to get favorites dao") .remove_favorite(user_id, path); }) - .await - .unwrap(); + .await + .unwrap(); info!( "Removing favorite \"{}\" for userid: {}", @@ -388,7 +389,7 @@ fn create_thumbnails() { .parent() .unwrap_or_else(|| panic!("Thumbnail {:?} has no parent?", thumb_path)), ) - .expect("Error creating directory"); + .expect("Error creating directory"); debug!("Generating video thumbnail: {:?}", thumb_path); generate_video_thumbnail(entry.path(), &thumb_path); @@ -521,10 +522,10 @@ fn main() -> std::io::Result<()> { .app_data::>>(Data::new(Mutex::new(tag_dao))) .wrap(prometheus.clone()) }) - .bind(dotenv::var("BIND_URL").unwrap())? - .bind("localhost:8088")? - .run() - .await + .bind(dotenv::var("BIND_URL").unwrap())? + .bind("localhost:8088")? + .run() + .await }) } -- 2.49.1