diff --git a/src/admin/media/commands.rs b/src/admin/media/commands.rs index 7aed28db3..4822296a3 100644 --- a/src/admin/media/commands.rs +++ b/src/admin/media/commands.rs @@ -360,7 +360,7 @@ pub(super) async fn get_remote_thumbnail( ) -> Result { let mxc: Mxc<'_> = mxc.as_str().try_into()?; let timeout = Duration::from_millis(timeout.into()); - let dim = Dim::new(width, height, None); + let dim = Dim::new(width, height, None, None); let mut result = self .services .media diff --git a/src/api/client/media.rs b/src/api/client/media.rs index 3f491d54f..551fbac76 100644 --- a/src/api/client/media.rs +++ b/src/api/client/media.rs @@ -99,7 +99,7 @@ pub(crate) async fn get_content_thumbnail_route( ) -> Result { let user = body.sender_user(); - let dim = Dim::from_ruma(body.width, body.height, body.method.clone())?; + let dim = Dim::from_ruma(body.width, body.height, body.method.clone(), body.animated)?; let mxc = Mxc { server_name: &body.server_name, media_id: &body.media_id, diff --git a/src/api/client/media_legacy.rs b/src/api/client/media_legacy.rs index 930daab47..765171c15 100644 --- a/src/api/client/media_legacy.rs +++ b/src/api/client/media_legacy.rs @@ -322,7 +322,7 @@ pub(crate) async fn get_content_thumbnail_legacy_route( media_id: &body.media_id, }; - let dim = Dim::from_ruma(body.width, body.height, body.method.clone())?; + let dim = Dim::from_ruma(body.width, body.height, body.method.clone(), body.animated)?; match services.media.get_thumbnail(&mxc, &dim).await? { | Some(FileMeta { content, diff --git a/src/api/server/media.rs b/src/api/server/media.rs index cbe8595bd..9d121b85b 100644 --- a/src/api/server/media.rs +++ b/src/api/server/media.rs @@ -67,7 +67,7 @@ pub(crate) async fn get_content_thumbnail_route( InsecureClientIp(client): InsecureClientIp, body: Ruma, ) -> Result { - let dim = Dim::from_ruma(body.width, body.height, body.method.clone())?; + let dim = Dim::from_ruma(body.width, body.height, body.method.clone(), body.animated)?; let mxc = Mxc { server_name: services.globals.server_name(), media_id: &body.media_id, diff --git a/src/service/media/remote.rs b/src/service/media/remote.rs index f234fa131..b09c618e4 100644 --- a/src/service/media/remote.rs +++ b/src/service/media/remote.rs @@ -372,7 +372,7 @@ pub async fn fetch_remote_thumbnail_legacy( }) .await?; - let dim = Dim::from_ruma(body.width, body.height, body.method.clone())?; + let dim = Dim::from_ruma(body.width, body.height, body.method.clone(), body.animated)?; self.upload_thumbnail( &mxc, None, diff --git a/src/service/media/thumbnail.rs b/src/service/media/thumbnail.rs index e5a987742..390f23d5c 100644 --- a/src/service/media/thumbnail.rs +++ b/src/service/media/thumbnail.rs @@ -16,12 +16,13 @@ use tokio::{ use super::{FileMeta, data::Metadata}; -/// Dimension specification for a thumbnail. +/// Dimension and format specification for a thumbnail. #[derive(Debug)] pub struct Dim { pub width: u32, pub height: u32, pub method: Method, + pub animated: bool, } impl super::Service { @@ -179,8 +180,14 @@ fn into_filemeta(data: Metadata, content: Vec) -> FileMeta { } impl Dim { - /// Instantiate a Dim from Ruma integers with optional method. - pub fn from_ruma(width: UInt, height: UInt, method: Option) -> Result { + /// Instantiate a Dim from Ruma integers with optional method and animation + /// flag. + pub fn from_ruma( + width: UInt, + height: UInt, + method: Option, + animated: Option, + ) -> Result { let width = width .try_into() .map_err(|e| err!(Request(InvalidParam("Width is invalid: {e:?}"))))?; @@ -188,17 +195,19 @@ impl Dim { .try_into() .map_err(|e| err!(Request(InvalidParam("Height is invalid: {e:?}"))))?; - Ok(Self::new(width, height, method)) + Ok(Self::new(width, height, method, animated)) } - /// Instantiate a Dim with optional method + /// Instantiate a Dim with optional method and animation flag. #[inline] #[must_use] - pub fn new(width: u32, height: u32, method: Option) -> Self { + pub fn new(width: u32, height: u32, method: Option, animated: Option) -> Self { Self { width, height, method: method.unwrap_or(Method::Scale), + // "When not provided, the server SHOULD NOT return an animated thumbnail" + animated: animated.unwrap_or(false), } } @@ -229,6 +238,7 @@ impl Dim { width: x, height: y, method: Method::Scale, + animated: self.animated, }) } @@ -238,11 +248,11 @@ impl Dim { #[must_use] pub fn normalized(&self) -> Self { match (self.width, self.height) { - | (0..=32, 0..=32) => Self::new(32, 32, Some(Method::Crop)), - | (0..=96, 0..=96) => Self::new(96, 96, Some(Method::Crop)), - | (0..=320, 0..=240) => Self::new(320, 240, Some(Method::Scale)), - | (0..=640, 0..=480) => Self::new(640, 480, Some(Method::Scale)), - | (0..=800, 0..=600) => Self::new(800, 600, Some(Method::Scale)), + | (0..=32, 0..=32) => Self::new(32, 32, Some(Method::Crop), Some(self.animated)), + | (0..=96, 0..=96) => Self::new(96, 96, Some(Method::Crop), Some(self.animated)), + | (0..=320, 0..=240) => Self::new(320, 240, Some(Method::Scale), Some(self.animated)), + | (0..=640, 0..=480) => Self::new(640, 480, Some(Method::Scale), Some(self.animated)), + | (0..=800, 0..=600) => Self::new(800, 600, Some(Method::Scale), Some(self.animated)), | _ => Self::default(), } } @@ -260,6 +270,7 @@ impl Default for Dim { width: 0, height: 0, method: Method::Scale, + animated: false, } } }