Skip to content

Commit

Permalink
config options
Browse files Browse the repository at this point in the history
  • Loading branch information
Nutomic committed Dec 13, 2024
1 parent e815778 commit 60ba7af
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
4 changes: 4 additions & 0 deletions config/defaults.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
11 changes: 6 additions & 5 deletions crates/routes/src/images/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -85,7 +85,7 @@ where
SendStream { rx }
}

pub(super) struct SendStream<T> {
struct SendStream<T> {
rx: tokio::sync::mpsc::Receiver<T>,
}

Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 12 additions & 0 deletions crates/utils/src/settings/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit 60ba7af

Please sign in to comment.