fix: release db connection
This commit is contained in:
parent
0bd531a21d
commit
71f6f47a00
@ -389,31 +389,36 @@ pub async fn get_blob_thumb(
|
|||||||
if id.len() != 32 {
|
if id.len() != 32 {
|
||||||
return Err(Status::NotFound);
|
return Err(Status::NotFound);
|
||||||
}
|
}
|
||||||
if let Ok(Some(info)) = db.get_file(&id).await {
|
let info = if let Ok(Some(info)) = db.get_file(&id).await {
|
||||||
let file_path = fs.get(&id);
|
info
|
||||||
|
} else {
|
||||||
|
return Err(Status::NotFound);
|
||||||
|
};
|
||||||
|
|
||||||
let mut thumb_file = temp_dir().join(format!("thumb_{}", sha256));
|
let file_path = fs.get(&id);
|
||||||
thumb_file.set_extension("webp");
|
|
||||||
|
|
||||||
if !thumb_file.exists() {
|
let mut thumb_file = temp_dir().join(format!("thumb_{}", sha256));
|
||||||
let mut p = WebpProcessor::new();
|
thumb_file.set_extension("webp");
|
||||||
if p.thumbnail(&file_path, &thumb_file).is_err() {
|
|
||||||
return Err(Status::InternalServerError);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Ok(f) = File::open(&thumb_file).await {
|
if !thumb_file.exists() {
|
||||||
return Ok(FilePayload {
|
let mut p = WebpProcessor::new();
|
||||||
file: f,
|
if p.thumbnail(&file_path, &thumb_file).is_err() {
|
||||||
info: FileUpload {
|
return Err(Status::InternalServerError);
|
||||||
size: thumb_file.metadata().unwrap().len(),
|
|
||||||
mime_type: "image/webp".to_string(),
|
|
||||||
..info
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Ok(f) = File::open(&thumb_file).await {
|
||||||
|
Ok(FilePayload {
|
||||||
|
file: f,
|
||||||
|
info: FileUpload {
|
||||||
|
size: thumb_file.metadata().unwrap().len(),
|
||||||
|
mime_type: "image/webp".to_string(),
|
||||||
|
..info
|
||||||
|
},
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
Err(Status::NotFound)
|
||||||
}
|
}
|
||||||
Err(Status::NotFound)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Legacy URL redirect for void.cat uploads
|
/// Legacy URL redirect for void.cat uploads
|
||||||
|
Loading…
x
Reference in New Issue
Block a user