mirror of
https://github.com/LemmyNet/lemmy.git
synced 2025-03-13 06:52:41 +00:00
Add more options for image uploads (#5483)
* Add more options for image uploads * remove separate option for animations * add comment
This commit is contained in:
parent
1e02dea397
commit
b14c6ae0ee
3 changed files with 28 additions and 7 deletions
|
@ -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
|
||||
|
|
|
@ -174,10 +174,13 @@ pub async fn do_upload_image(
|
|||
context: &Data<LemmyContext>,
|
||||
) -> LemmyResult<UploadImageResponse> {
|
||||
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())
|
||||
|
|
|
@ -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<u32>,
|
||||
|
||||
/// 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)]
|
||||
|
|
Loading…
Reference in a new issue