diff --git a/config/defaults.hjson b/config/defaults.hjson index ffc08ebd9..7b34f38b0 100644 --- a/config/defaults.hjson +++ b/config/defaults.hjson @@ -59,11 +59,15 @@ 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. + # Maximum size for user avatar, community icon and site icon. Larger images are downscaled. max_avatar_size: 512 - # Maximum size for user, community and site banner. Larger images are downscaled to fit - # into a square of this size. + # Maximum size for user, community and site banner. Larger images are downscaled. max_banner_size: 1024 + # Maximum size for other uploads (e.g. post images or markdown embed images). Larger + # images are downscaled. + max_upload_size: 1024 + # Whether users can upload videos as post image or markdown embed. + allow_video_uploads: true # Prevent users from uploading images for posts or embedding in markdown. Avatars, icons and # banners can still be uploaded. image_upload_disabled: false diff --git a/crates/routes/src/images/upload.rs b/crates/routes/src/images/upload.rs index 6ddc08458..8ceb6c22e 100644 --- a/crates/routes/src/images/upload.rs +++ b/crates/routes/src/images/upload.rs @@ -174,10 +174,13 @@ pub async fn do_upload_image( context: &Data, ) -> LemmyResult { let pictrs = context.settings().pictrs()?; + let max_upload_size = pictrs.max_upload_size.map(|m| m.to_string()); let image_url = format!("{}image", pictrs.url); let mut client_req = adapt_request(&req, image_url, context); + // Set pictrs parameters to downscale images and restrict file types. + // https://git.asonix.dog/asonix/pict-rs/#api client_req = match upload_type { Avatar => { let max_size = pictrs.max_avatar_size.to_string(); @@ -195,7 +198,13 @@ pub async fn do_upload_image( ("allow_video", "false"), ]) } - _ => client_req, + Other => { + let mut query = vec![("allow_video", pictrs.allow_video_uploads.to_string())]; + if let Some(max_upload_size) = max_upload_size { + query.push(("resize", max_upload_size)); + } + client_req.query(&query) + } }; if let Some(addr) = req.head().peer_addr { client_req = client_req.header("X-Forwarded-For", addr.to_string()) diff --git a/crates/utils/src/settings/structs.rs b/crates/utils/src/settings/structs.rs index 37c520032..1ab5b64da 100644 --- a/crates/utils/src/settings/structs.rs +++ b/crates/utils/src/settings/structs.rs @@ -95,15 +95,23 @@ pub struct PictrsConfig { #[default(512)] pub max_thumbnail_size: u32, - /// Maximum size for user avatar, community icon and site icon. + /// Maximum size for user avatar, community icon and site icon. Larger images are downscaled. #[default(512)] pub max_avatar_size: u32, - /// Maximum size for user, community and site banner. Larger images are downscaled to fit - /// into a square of this size. + /// Maximum size for user, community and site banner. Larger images are downscaled. #[default(1024)] pub max_banner_size: u32, + /// Maximum size for other uploads (e.g. post images or markdown embed images). Larger + /// images are downscaled. + #[doku(example = "1024")] + pub max_upload_size: Option, + + /// Whether users can upload videos as post image or markdown embed. + #[default(true)] + pub allow_video_uploads: bool, + /// Prevent users from uploading images for posts or embedding in markdown. Avatars, icons and /// banners can still be uploaded. #[default(false)]