mirror of
https://git.asonix.dog/asonix/pict-rs
synced 2024-12-22 19:31:35 +00:00
Put image crate actions behind web::block
This commit is contained in:
parent
fc1ae4be49
commit
d71b86a81e
1 changed files with 10 additions and 6 deletions
|
@ -191,10 +191,13 @@ impl UploadManager {
|
||||||
let bytes = bytes.freeze();
|
let bytes = bytes.freeze();
|
||||||
|
|
||||||
// -- VALIDATE IMAGE --
|
// -- VALIDATE IMAGE --
|
||||||
let format = image::guess_format(&bytes).map_err(UploadError::InvalidImage)?;
|
web::block(move || {
|
||||||
let img = image::load_from_memory(&bytes).map_err(UploadError::InvalidImage)?;
|
let format = image::guess_format(&bytes).map_err(UploadError::InvalidImage)?;
|
||||||
|
let img = image::load_from_memory(&bytes).map_err(UploadError::InvalidImage)?;
|
||||||
|
|
||||||
(img, format)
|
Ok((img, format)) as Result<(image::DynamicImage, image::ImageFormat), UploadError>
|
||||||
|
})
|
||||||
|
.await?
|
||||||
};
|
};
|
||||||
|
|
||||||
let (format, content_type) = self
|
let (format, content_type) = self
|
||||||
|
@ -208,11 +211,12 @@ impl UploadManager {
|
||||||
return Err(UploadError::ContentType(content_type));
|
return Err(UploadError::ContentType(content_type));
|
||||||
}
|
}
|
||||||
|
|
||||||
let bytes: bytes::Bytes = {
|
let bytes: bytes::Bytes = web::block(move || {
|
||||||
let mut bytes = std::io::Cursor::new(vec![]);
|
let mut bytes = std::io::Cursor::new(vec![]);
|
||||||
img.write_to(&mut bytes, format)?;
|
img.write_to(&mut bytes, format)?;
|
||||||
bytes::Bytes::from(bytes.into_inner())
|
Ok(bytes::Bytes::from(bytes.into_inner())) as Result<bytes::Bytes, UploadError>
|
||||||
};
|
})
|
||||||
|
.await?;
|
||||||
|
|
||||||
// -- DUPLICATE CHECKS --
|
// -- DUPLICATE CHECKS --
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue