mirror of
https://gitlab.com/famedly/conduit.git
synced 2025-06-27 16:35:59 +00:00
fix(media): return an error when content is failed to be parsed as an image
This commit is contained in:
parent
e952522a39
commit
30855cef81
2 changed files with 12 additions and 10 deletions
|
@ -348,9 +348,9 @@ async fn get_content_thumbnail(
|
||||||
) -> Result<get_content_thumbnail::v1::Response, Error> {
|
) -> Result<get_content_thumbnail::v1::Response, Error> {
|
||||||
let mxc = format!("mxc://{}/{}", server_name, media_id);
|
let mxc = format!("mxc://{}/{}", server_name, media_id);
|
||||||
|
|
||||||
if let Ok(Some(FileMeta {
|
if let Some(FileMeta {
|
||||||
file, content_type, ..
|
file, content_type, ..
|
||||||
})) = services()
|
}) = services()
|
||||||
.media
|
.media
|
||||||
.get_thumbnail(
|
.get_thumbnail(
|
||||||
mxc.clone(),
|
mxc.clone(),
|
||||||
|
@ -361,7 +361,7 @@ async fn get_content_thumbnail(
|
||||||
.try_into()
|
.try_into()
|
||||||
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Height is invalid."))?,
|
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Height is invalid."))?,
|
||||||
)
|
)
|
||||||
.await
|
.await?
|
||||||
{
|
{
|
||||||
Ok(get_content_thumbnail::v1::Response { file, content_type })
|
Ok(get_content_thumbnail::v1::Response { file, content_type })
|
||||||
} else if server_name != services().globals.server_name() && allow_remote {
|
} else if server_name != services().globals.server_name() && allow_remote {
|
||||||
|
|
|
@ -2,7 +2,10 @@ mod data;
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
|
|
||||||
pub use data::Data;
|
pub use data::Data;
|
||||||
use ruma::http_headers::{ContentDisposition, ContentDispositionType};
|
use ruma::{
|
||||||
|
api::client::error::ErrorKind,
|
||||||
|
http_headers::{ContentDisposition, ContentDispositionType},
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{services, Result};
|
use crate::{services, Result};
|
||||||
use image::imageops::FilterType;
|
use image::imageops::FilterType;
|
||||||
|
@ -219,12 +222,11 @@ impl Service {
|
||||||
file: thumbnail_bytes.to_vec(),
|
file: thumbnail_bytes.to_vec(),
|
||||||
}))
|
}))
|
||||||
} else {
|
} else {
|
||||||
// Couldn't parse file to generate thumbnail, send original
|
// Couldn't parse file to generate thumbnail, likely not an image
|
||||||
Ok(Some(FileMeta {
|
return Err(crate::Error::BadRequest(
|
||||||
content_disposition,
|
ErrorKind::Unknown,
|
||||||
content_type,
|
"Unable to generate thumbnail for the requested content (likely is not an image)",
|
||||||
file: file.to_vec(),
|
));
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue