diff --git a/CHANGELOG.md b/CHANGELOG.md index 38b6e49..2066882 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Use `mediaType` property value to determine file extension when saving downloaded media. - Added `mediaType` property to images in actor object. - Prevent `delete-extraneous-posts` command from deleting post if there's a recent reply or repost. +- Changed max actor image size to 5 MB. ### Removed diff --git a/src/activitypub/actors/helpers.rs b/src/activitypub/actors/helpers.rs index 159b469..e7547f9 100644 --- a/src/activitypub/actors/helpers.rs +++ b/src/activitypub/actors/helpers.rs @@ -19,6 +19,8 @@ use crate::models::profiles::{ }, }; +const ACTOR_IMAGE_MAX_SIZE: u64 = 5 * 1000 * 1000; // 5 MB + async fn fetch_actor_images( instance: &Instance, actor: &Actor, @@ -31,6 +33,7 @@ async fn fetch_actor_images( instance, &icon.url, icon.media_type.as_deref(), + ACTOR_IMAGE_MAX_SIZE, media_dir, ).await { Ok((file_name, maybe_media_type)) => { @@ -53,6 +56,7 @@ async fn fetch_actor_images( instance, &image.url, image.media_type.as_deref(), + ACTOR_IMAGE_MAX_SIZE, media_dir, ).await { Ok((file_name, maybe_media_type)) => { diff --git a/src/activitypub/fetcher/fetchers.rs b/src/activitypub/fetcher/fetchers.rs index 4842b92..4ad07ee 100644 --- a/src/activitypub/fetcher/fetchers.rs +++ b/src/activitypub/fetcher/fetchers.rs @@ -104,12 +104,11 @@ async fn send_request( Ok(data) } -const FILE_MAX_SIZE: u64 = 1024 * 1024 * 20; - pub async fn fetch_file( instance: &Instance, url: &str, maybe_media_type: Option<&str>, + file_max_size: u64, output_dir: &Path, ) -> Result<(String, Option), FetchError> { let client = build_client(instance)?; @@ -117,12 +116,12 @@ pub async fn fetch_file( build_request(instance, client, Method::GET, url); let response = request_builder.send().await?.error_for_status()?; if let Some(file_size) = response.content_length() { - if file_size > FILE_MAX_SIZE { + if file_size > file_max_size { return Err(FetchError::OtherError("file is too large")); }; }; let file_data = response.bytes().await?; - if file_data.len() > FILE_MAX_SIZE as usize { + if file_data.len() > file_max_size as usize { return Err(FetchError::OtherError("file is too large")); }; let maybe_media_type = maybe_media_type diff --git a/src/activitypub/handlers/create.rs b/src/activitypub/handlers/create.rs index a7e8334..9c08c6b 100644 --- a/src/activitypub/handlers/create.rs +++ b/src/activitypub/handlers/create.rs @@ -126,6 +126,8 @@ fn get_note_visibility( Visibility::Direct } +const ATTACHMENT_MAX_SIZE: u64 = 20 * 1000 * 1000; + pub async fn handle_note( db_client: &mut impl GenericClient, instance: &Instance, @@ -183,6 +185,7 @@ pub async fn handle_note( instance, &attachment_url, attachment.media_type.as_deref(), + ATTACHMENT_MAX_SIZE, media_dir, ).await .map_err(|err| {