Merge pull request 'Use PhotoSize enum in file requests' (#29) from feature/photosize-enum into master

Reviewed-on: #29
This commit was merged in pull request #29.
This commit is contained in:
2024-06-30 21:51:28 +00:00
2 changed files with 21 additions and 12 deletions

View File

@@ -103,7 +103,8 @@ pub struct PhotosResponse {
#[derive(Deserialize)]
pub struct FilesRequest {
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 recursive: Option<bool>,
}
@@ -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<String>,
pub size: Option<PhotoSize>,
}
#[derive(Deserialize)]

View File

@@ -80,7 +80,8 @@ async fn get_image(
app_state: Data<AppState>,
) -> 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::<i32>().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<Mutex<SqliteTagDao>>>(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
})
}