config options

This commit is contained in:
Felix Ableitner 2024-12-13 15:23:05 +01:00
parent e815778926
commit 60ba7af2a1
3 changed files with 22 additions and 5 deletions

View file

@ -64,6 +64,10 @@
upload_timeout: 30 upload_timeout: 30
# Resize post thumbnails to this maximum width/height. # Resize post thumbnails to this maximum width/height.
max_thumbnail_size: 512 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 sending configuration. All options except login/password are mandatory
email: { email: {

View file

@ -61,7 +61,7 @@ fn adapt_request(request: &HttpRequest, url: String) -> RequestBuilder {
}) })
} }
pub(super) fn make_send<S>(mut stream: S) -> impl Stream<Item = S::Item> + Send + Unpin + 'static fn make_send<S>(mut stream: S) -> impl Stream<Item = S::Item> + Send + Unpin + 'static
where where
S: Stream + Unpin + 'static, S: Stream + Unpin + 'static,
S::Item: Send, S::Item: Send,
@ -85,7 +85,7 @@ where
SendStream { rx } SendStream { rx }
} }
pub(super) struct SendStream<T> { struct SendStream<T> {
rx: tokio::sync::mpsc::Receiver<T>, rx: tokio::sync::mpsc::Receiver<T>,
} }
@ -135,15 +135,16 @@ pub(super) async fn do_upload_image(
let max_size = context let max_size = context
.settings() .settings()
.pictrs_config()? .pictrs_config()?
.max_thumbnail_size .max_avatar_size
.to_string(); .to_string();
client_req.query(&[ client_req.query(&[
("max_width", max_size.as_ref()), ("resize", max_size.as_ref()),
("max_height", max_size.as_ref()),
("allow_animation", "false"), ("allow_animation", "false"),
("allow_video", "false"), ("allow_video", "false"),
]) ])
} }
// TODO: same as above but using `max_banner_size`
// UploadType::Banner => {}
_ => client_req, _ => client_req,
}; };
if let Some(addr) = req.head().peer_addr { if let Some(addr) = req.head().peer_addr {

View file

@ -104,6 +104,18 @@ pub struct PictrsConfig {
/// Resize post thumbnails to this maximum width/height. /// Resize post thumbnails to this maximum width/height.
#[default(512)] #[default(512)]
pub max_thumbnail_size: u32, 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)] #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document, PartialEq)]