Check extensions case-invariant
Ran clippy and linted some of the logic.
This commit is contained in:
21
src/main.rs
21
src/main.rs
@@ -113,7 +113,7 @@ async fn get_image(
|
|||||||
req: web::Query<ThumbnailRequest>,
|
req: web::Query<ThumbnailRequest>,
|
||||||
) -> impl Responder {
|
) -> impl Responder {
|
||||||
if let Some(path) = is_valid_path(&req.path) {
|
if let Some(path) = is_valid_path(&req.path) {
|
||||||
if let Some(_) = req.size {
|
if req.size.is_some() {
|
||||||
let thumbs = dotenv::var("THUMBNAILS").unwrap();
|
let thumbs = dotenv::var("THUMBNAILS").unwrap();
|
||||||
let thumb_path = Path::new(&thumbs).join(path.file_name().unwrap());
|
let thumb_path = Path::new(&thumbs).join(path.file_name().unwrap());
|
||||||
|
|
||||||
@@ -123,12 +123,10 @@ async fn get_image(
|
|||||||
} else {
|
} else {
|
||||||
HttpResponse::NotFound().finish()
|
HttpResponse::NotFound().finish()
|
||||||
}
|
}
|
||||||
} else {
|
} else if let Ok(file) = NamedFile::open(path) {
|
||||||
if let Ok(file) = NamedFile::open(path) {
|
|
||||||
file.into_response(&request).unwrap()
|
file.into_response(&request).unwrap()
|
||||||
} else {
|
} else {
|
||||||
HttpResponse::NotFound().finish()
|
HttpResponse::NotFound().finish()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
HttpResponse::BadRequest().finish()
|
HttpResponse::BadRequest().finish()
|
||||||
@@ -186,7 +184,7 @@ async fn create_thumbnails() {
|
|||||||
.read_dir()
|
.read_dir()
|
||||||
.expect("Error reading thumbnail directory")
|
.expect("Error reading thumbnail directory")
|
||||||
.collect();
|
.collect();
|
||||||
if t.len() > 0 {
|
if !t.is_empty() {
|
||||||
println!("Skipping thumbs");
|
println!("Skipping thumbs");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -200,9 +198,12 @@ async fn create_thumbnails() {
|
|||||||
.filter_map(|entry| entry.ok())
|
.filter_map(|entry| entry.ok())
|
||||||
.filter(|entry| {
|
.filter(|entry| {
|
||||||
println!("{:?}", entry.path());
|
println!("{:?}", entry.path());
|
||||||
match entry.path().extension() {
|
if let Some(ext) = entry.path().extension().and_then(|ext| {
|
||||||
Some(ext) if ext == "jpg" || ext == "jpeg" || ext == "png" => true,
|
ext.to_str().map(|ext| ext.to_lowercase())
|
||||||
_ => false,
|
}) {
|
||||||
|
ext == "jpg" || ext == "jpeg" || ext == "png"
|
||||||
|
} else {
|
||||||
|
false
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.map(|entry| (image::open(entry.path()), entry.path().to_path_buf()))
|
.map(|entry| (image::open(entry.path()), entry.path().to_path_buf()))
|
||||||
|
|||||||
Reference in New Issue
Block a user