mirror of
https://gitlab.com/famedly/conduit.git
synced 2025-04-22 14:10:16 +03:00
Merge branch 'error-parse-image-thumbnail' into 'next'
fix(media): return an error when content is failed to be parsed as an image See merge request famedly/conduit!734
This commit is contained in:
commit
e20dd1469a
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> {
|
||||
let mxc = format!("mxc://{}/{}", server_name, media_id);
|
||||
|
||||
if let Ok(Some(FileMeta {
|
||||
if let Some(FileMeta {
|
||||
file, content_type, ..
|
||||
})) = services()
|
||||
}) = services()
|
||||
.media
|
||||
.get_thumbnail(
|
||||
mxc.clone(),
|
||||
|
@ -361,7 +361,7 @@ async fn get_content_thumbnail(
|
|||
.try_into()
|
||||
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Height is invalid."))?,
|
||||
)
|
||||
.await
|
||||
.await?
|
||||
{
|
||||
Ok(get_content_thumbnail::v1::Response { file, content_type })
|
||||
} else if server_name != services().globals.server_name() && allow_remote {
|
||||
|
|
|
@ -2,7 +2,10 @@ mod data;
|
|||
use std::io::Cursor;
|
||||
|
||||
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 image::imageops::FilterType;
|
||||
|
@ -219,12 +222,11 @@ impl Service {
|
|||
file: thumbnail_bytes.to_vec(),
|
||||
}))
|
||||
} else {
|
||||
// Couldn't parse file to generate thumbnail, send original
|
||||
Ok(Some(FileMeta {
|
||||
content_disposition,
|
||||
content_type,
|
||||
file: file.to_vec(),
|
||||
}))
|
||||
// Couldn't parse file to generate thumbnail, likely not an image
|
||||
return Err(crate::Error::BadRequest(
|
||||
ErrorKind::Unknown,
|
||||
"Unable to generate thumbnail for the requested content (likely is not an image)",
|
||||
));
|
||||
}
|
||||
} else {
|
||||
Ok(None)
|
||||
|
|
Loading…
Reference in a new issue