Use PhotoSize enum in file requests #29

Merged
cameron merged 1 commits from feature/photosize-enum into master 2024-06-30 21:51:29 +00:00
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");
@@ -279,7 +280,7 @@ async fn favorites(
.expect("Unable to get FavoritesDao") .expect("Unable to get FavoritesDao")
.get_favorites(claims.sub.parse::<i32>().unwrap()) .get_favorites(claims.sub.parse::<i32>().unwrap())
}) })
.await .await
{ {
Ok(Ok(favorites)) => { Ok(Ok(favorites)) => {
let favorites = favorites let favorites = favorites
@@ -314,7 +315,7 @@ async fn put_add_favorite(
.expect("Unable to get FavoritesDao") .expect("Unable to get FavoritesDao")
.add_favorite(user_id, &path) .add_favorite(user_id, &path)
}) })
.await .await
{ {
Ok(Err(e)) if e.kind == DbErrorKind::AlreadyExists => { Ok(Err(e)) if e.kind == DbErrorKind::AlreadyExists => {
debug!("Favorite: {} exists for user: {}", &body.path, user_id); debug!("Favorite: {} exists for user: {}", &body.path, user_id);
@@ -353,8 +354,8 @@ async fn delete_favorite(
.expect("Unable to get favorites dao") .expect("Unable to get favorites dao")
.remove_favorite(user_id, path); .remove_favorite(user_id, path);
}) })
.await .await
.unwrap(); .unwrap();
info!( info!(
"Removing favorite \"{}\" for userid: {}", "Removing favorite \"{}\" for userid: {}",
@@ -388,7 +389,7 @@ fn create_thumbnails() {
.parent() .parent()
.unwrap_or_else(|| panic!("Thumbnail {:?} has no parent?", thumb_path)), .unwrap_or_else(|| panic!("Thumbnail {:?} has no parent?", thumb_path)),
) )
.expect("Error creating directory"); .expect("Error creating directory");
debug!("Generating video thumbnail: {:?}", thumb_path); debug!("Generating video thumbnail: {:?}", thumb_path);
generate_video_thumbnail(entry.path(), &thumb_path); generate_video_thumbnail(entry.path(), &thumb_path);
@@ -521,10 +522,10 @@ fn main() -> std::io::Result<()> {
.app_data::<Data<Mutex<SqliteTagDao>>>(Data::new(Mutex::new(tag_dao))) .app_data::<Data<Mutex<SqliteTagDao>>>(Data::new(Mutex::new(tag_dao)))
.wrap(prometheus.clone()) .wrap(prometheus.clone())
}) })
.bind(dotenv::var("BIND_URL").unwrap())? .bind(dotenv::var("BIND_URL").unwrap())?
.bind("localhost:8088")? .bind("localhost:8088")?
.run() .run()
.await .await
}) })
} }