mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-14 20:56:49 +00:00
feat: Add animated flag to Dim
This commit is contained in:
6 files changed
+27
-16
No files matched your search
@@ -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
|
||||
|
||||
@@ -99,7 +99,7 @@ pub(crate) async fn get_content_thumbnail_route(
|
||||
) -> Result<get_content_thumbnail::v1::Response> {
|
||||
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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -67,7 +67,7 @@ pub(crate) async fn get_content_thumbnail_route(
|
||||
InsecureClientIp(client): InsecureClientIp,
|
||||
body: Ruma<get_content_thumbnail::v1::Request>,
|
||||
) -> Result<get_content_thumbnail::v1::Response> {
|
||||
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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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<u8>) -> FileMeta {
|
||||
}
|
||||
|
||||
impl Dim {
|
||||
/// Instantiate a Dim from Ruma integers with optional method.
|
||||
pub fn from_ruma(width: UInt, height: UInt, method: Option<Method>) -> Result<Self> {
|
||||
/// Instantiate a Dim from Ruma integers with optional method and animation
|
||||
/// flag.
|
||||
pub fn from_ruma(
|
||||
width: UInt,
|
||||
height: UInt,
|
||||
method: Option<Method>,
|
||||
animated: Option<bool>,
|
||||
) -> Result<Self> {
|
||||
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<Method>) -> Self {
|
||||
pub fn new(width: u32, height: u32, method: Option<Method>, animated: Option<bool>) -> 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,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user