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>,
|
||||
) -> impl Responder {
|
||||
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 thumb_path = Path::new(&thumbs).join(path.file_name().unwrap());
|
||||
|
||||
@@ -123,12 +123,10 @@ async fn get_image(
|
||||
} else {
|
||||
HttpResponse::NotFound().finish()
|
||||
}
|
||||
} else {
|
||||
if let Ok(file) = NamedFile::open(path) {
|
||||
} else if let Ok(file) = NamedFile::open(path) {
|
||||
file.into_response(&request).unwrap()
|
||||
} else {
|
||||
HttpResponse::NotFound().finish()
|
||||
}
|
||||
} else {
|
||||
HttpResponse::NotFound().finish()
|
||||
}
|
||||
} else {
|
||||
HttpResponse::BadRequest().finish()
|
||||
@@ -186,7 +184,7 @@ async fn create_thumbnails() {
|
||||
.read_dir()
|
||||
.expect("Error reading thumbnail directory")
|
||||
.collect();
|
||||
if t.len() > 0 {
|
||||
if !t.is_empty() {
|
||||
println!("Skipping thumbs");
|
||||
return;
|
||||
}
|
||||
@@ -200,9 +198,12 @@ async fn create_thumbnails() {
|
||||
.filter_map(|entry| entry.ok())
|
||||
.filter(|entry| {
|
||||
println!("{:?}", entry.path());
|
||||
match entry.path().extension() {
|
||||
Some(ext) if ext == "jpg" || ext == "jpeg" || ext == "png" => true,
|
||||
_ => false,
|
||||
if let Some(ext) = entry.path().extension().and_then(|ext| {
|
||||
ext.to_str().map(|ext| ext.to_lowercase())
|
||||
}) {
|
||||
ext == "jpg" || ext == "jpeg" || ext == "png"
|
||||
} else {
|
||||
false
|
||||
}
|
||||
})
|
||||
.map(|entry| (image::open(entry.path()), entry.path().to_path_buf()))
|
||||
|
||||
Reference in New Issue
Block a user