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.
- 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

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(
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)) => {

View file

@ -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<String>), 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

View file

@ -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| {