diff --git a/config/defaults.hjson b/config/defaults.hjson index 14749e542e..c1cb8d06b4 100644 --- a/config/defaults.hjson +++ b/config/defaults.hjson @@ -64,6 +64,10 @@ upload_timeout: 30 # Resize post thumbnails to this maximum width/height. max_thumbnail_size: 512 + # Maximum size for user avatar, community icon and site icon. + max_avatar_size: 512 + # Maximum size for user, community and site banner. + max_banner_size: 512 } # Email sending configuration. All options except login/password are mandatory email: { diff --git a/crates/routes/src/images/utils.rs b/crates/routes/src/images/utils.rs index dcc4188272..e4b2432014 100644 --- a/crates/routes/src/images/utils.rs +++ b/crates/routes/src/images/utils.rs @@ -61,7 +61,7 @@ fn adapt_request(request: &HttpRequest, url: String) -> RequestBuilder { }) } -pub(super) fn make_send(mut stream: S) -> impl Stream + Send + Unpin + 'static +fn make_send(mut stream: S) -> impl Stream + Send + Unpin + 'static where S: Stream + Unpin + 'static, S::Item: Send, @@ -85,7 +85,7 @@ where SendStream { rx } } -pub(super) struct SendStream { +struct SendStream { rx: tokio::sync::mpsc::Receiver, } @@ -135,15 +135,16 @@ pub(super) async fn do_upload_image( let max_size = context .settings() .pictrs_config()? - .max_thumbnail_size + .max_avatar_size .to_string(); client_req.query(&[ - ("max_width", max_size.as_ref()), - ("max_height", max_size.as_ref()), + ("resize", max_size.as_ref()), ("allow_animation", "false"), ("allow_video", "false"), ]) } + // TODO: same as above but using `max_banner_size` + // UploadType::Banner => {} _ => client_req, }; if let Some(addr) = req.head().peer_addr { diff --git a/crates/utils/src/settings/structs.rs b/crates/utils/src/settings/structs.rs index 9e561713c5..3048843936 100644 --- a/crates/utils/src/settings/structs.rs +++ b/crates/utils/src/settings/structs.rs @@ -104,6 +104,18 @@ pub struct PictrsConfig { /// Resize post thumbnails to this maximum width/height. #[default(512)] pub max_thumbnail_size: u32, + + /// Maximum size for user avatar, community icon and site icon. + #[default(512)] + pub max_avatar_size: u32, + + /// Maximum size for user, community and site banner. + /// + /// TODO: Unfortunately pictrs can only resize images to fit in a*a square, no rectangle. + /// Otherwise we have to use crop, or use max_width/max_height which throws error + /// if image is larger. + #[default(512)] + pub max_banner_size: u32, } #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document, PartialEq)]