Change max actor image size to 5 MB

This commit is contained in:
silverpill 2023-01-16 16:54:57 +00:00
parent 5809cffa71
commit 5064afd766
4 changed files with 11 additions and 4 deletions

View file

@ -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. - Use `mediaType` property value to determine file extension when saving downloaded media.
- Added `mediaType` property to images in actor object. - Added `mediaType` property to images in actor object.
- Prevent `delete-extraneous-posts` command from deleting post if there's a recent reply or repost. - 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 ### Removed

View file

@ -19,6 +19,8 @@ use crate::models::profiles::{
}, },
}; };
const ACTOR_IMAGE_MAX_SIZE: u64 = 5 * 1000 * 1000; // 5 MB
async fn fetch_actor_images( async fn fetch_actor_images(
instance: &Instance, instance: &Instance,
actor: &Actor, actor: &Actor,
@ -31,6 +33,7 @@ async fn fetch_actor_images(
instance, instance,
&icon.url, &icon.url,
icon.media_type.as_deref(), icon.media_type.as_deref(),
ACTOR_IMAGE_MAX_SIZE,
media_dir, media_dir,
).await { ).await {
Ok((file_name, maybe_media_type)) => { Ok((file_name, maybe_media_type)) => {
@ -53,6 +56,7 @@ async fn fetch_actor_images(
instance, instance,
&image.url, &image.url,
image.media_type.as_deref(), image.media_type.as_deref(),
ACTOR_IMAGE_MAX_SIZE,
media_dir, media_dir,
).await { ).await {
Ok((file_name, maybe_media_type)) => { Ok((file_name, maybe_media_type)) => {

View file

@ -104,12 +104,11 @@ async fn send_request(
Ok(data) Ok(data)
} }
const FILE_MAX_SIZE: u64 = 1024 * 1024 * 20;
pub async fn fetch_file( pub async fn fetch_file(
instance: &Instance, instance: &Instance,
url: &str, url: &str,
maybe_media_type: Option<&str>, maybe_media_type: Option<&str>,
file_max_size: u64,
output_dir: &Path, output_dir: &Path,
) -> Result<(String, Option<String>), FetchError> { ) -> Result<(String, Option<String>), FetchError> {
let client = build_client(instance)?; let client = build_client(instance)?;
@ -117,12 +116,12 @@ pub async fn fetch_file(
build_request(instance, client, Method::GET, url); build_request(instance, client, Method::GET, url);
let response = request_builder.send().await?.error_for_status()?; let response = request_builder.send().await?.error_for_status()?;
if let Some(file_size) = response.content_length() { 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")); return Err(FetchError::OtherError("file is too large"));
}; };
}; };
let file_data = response.bytes().await?; 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")); return Err(FetchError::OtherError("file is too large"));
}; };
let maybe_media_type = maybe_media_type let maybe_media_type = maybe_media_type

View file

@ -126,6 +126,8 @@ fn get_note_visibility(
Visibility::Direct Visibility::Direct
} }
const ATTACHMENT_MAX_SIZE: u64 = 20 * 1000 * 1000;
pub async fn handle_note( pub async fn handle_note(
db_client: &mut impl GenericClient, db_client: &mut impl GenericClient,
instance: &Instance, instance: &Instance,
@ -183,6 +185,7 @@ pub async fn handle_note(
instance, instance,
&attachment_url, &attachment_url,
attachment.media_type.as_deref(), attachment.media_type.as_deref(),
ATTACHMENT_MAX_SIZE,
media_dir, media_dir,
).await ).await
.map_err(|err| { .map_err(|err| {