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
# 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: {

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
S: Stream + Unpin + 'static,
S::Item: Send,
@ -85,7 +85,7 @@ where
SendStream { rx }
}
pub(super) struct SendStream<T> {
struct SendStream<T> {
rx: tokio::sync::mpsc::Receiver<T>,
}
@ -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 {

View file

@ -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)]