1
0
Fork 0
forked from mirror/grapevine

client_server: factor out width/height conversion

This commit is contained in:
Lambda 2024-08-25 17:25:51 +00:00
parent edfaa83405
commit 7f6ab63752

View file

@ -363,23 +363,19 @@ async fn get_content_thumbnail_route_ruma(
body: Ar<legacy_media::get_content_thumbnail::v3::Request>, body: Ar<legacy_media::get_content_thumbnail::v3::Request>,
) -> Result<legacy_media::get_content_thumbnail::v3::Response> { ) -> Result<legacy_media::get_content_thumbnail::v3::Response> {
let mxc = MxcData::new(&body.server_name, &body.media_id)?; let mxc = MxcData::new(&body.server_name, &body.media_id)?;
let width = body.width.try_into().map_err(|_| {
Error::BadRequest(ErrorKind::InvalidParam, "Width is invalid.")
})?;
let height = body.height.try_into().map_err(|_| {
Error::BadRequest(ErrorKind::InvalidParam, "Height is invalid.")
})?;
if let Some(FileMeta { if let Some(FileMeta {
content_type, content_type,
file, file,
.. ..
}) = services() }) =
.media services().media.get_thumbnail(mxc.to_string(), width, height).await?
.get_thumbnail(
mxc.to_string(),
body.width.try_into().map_err(|_| {
Error::BadRequest(ErrorKind::InvalidParam, "Width is invalid.")
})?,
body.height.try_into().map_err(|_| {
Error::BadRequest(ErrorKind::InvalidParam, "Width is invalid.")
})?,
)
.await?
{ {
Ok(legacy_media::get_content_thumbnail::v3::Response { Ok(legacy_media::get_content_thumbnail::v3::Response {
file, file,
@ -413,8 +409,8 @@ async fn get_content_thumbnail_route_ruma(
mxc.to_string(), mxc.to_string(),
None, None,
get_thumbnail_response.content_type.as_deref(), get_thumbnail_response.content_type.as_deref(),
body.width.try_into().expect("all UInts are valid u32s"), width,
body.height.try_into().expect("all UInts are valid u32s"), height,
&get_thumbnail_response.file, &get_thumbnail_response.file,
) )
.await?; .await?;