diff --git a/src/main.rs b/src/main.rs index eb5b6cc..a5024e5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -57,8 +57,20 @@ async fn handle_image_request(Path(path): Path) -> impl IntoResponse { return body.into_response(); } + let resize_width = path + .split('.') + .find(|s| s.starts_with("w")) + .and_then(|s| s.strip_prefix("w")) + .and_then(|s| s.parse::().ok()); + let extension = file_path.extension().and_then(|s| s.to_str()).unwrap_or(""); - let original_path = path.split('.').next().unwrap().to_string() + "." + extension; + let original_path = if resize_width.is_none() { + path.clone() + } else { + path.split('.').collect::>()[..path.split('.').count() - 2].join(".") + + "." + + extension + }; let original_file_path = PathBuf::from(format!("cdn_root/images/{}", original_path)); if !original_file_path.exists() { @@ -67,12 +79,6 @@ async fn handle_image_request(Path(path): Path) -> impl IntoResponse { } } - let resize_width = path - .split('.') - .find(|s| s.starts_with("w")) - .and_then(|s| s.strip_prefix("w")) - .and_then(|s| s.parse::().ok()); - if resize_width.is_none() { let file = match tokio::fs::File::open(file_path).await { Ok(file) => file,