diff --git a/src/mastodon_api/accounts/types.rs b/src/mastodon_api/accounts/types.rs index cb22c41..17157af 100644 --- a/src/mastodon_api/accounts/types.rs +++ b/src/mastodon_api/accounts/types.rs @@ -7,7 +7,7 @@ use uuid::Uuid; use crate::errors::{HttpError, ValidationError}; use crate::identity::did::Did; use crate::mastodon_api::pagination::PageSize; -use crate::mastodon_api::uploads::{UploadError, save_validated_b64_file}; +use crate::mastodon_api::uploads::{save_b64_file, UploadError}; use crate::models::profiles::types::{ DbActorProfile, ExtraField, @@ -230,8 +230,11 @@ fn process_b64_image_field_value( None } else { // Decode and save file - let (file_name, _) = save_validated_b64_file( - &b64_data, output_dir, "image/", + let (file_name, _) = save_b64_file( + &b64_data, + None, + output_dir, + Some("image/"), )?; Some(file_name) } diff --git a/src/mastodon_api/uploads.rs b/src/mastodon_api/uploads.rs index 47dd95e..eff4ea6 100644 --- a/src/mastodon_api/uploads.rs +++ b/src/mastodon_api/uploads.rs @@ -63,21 +63,3 @@ pub fn save_b64_file( )?; Ok((file_name, media_type)) } - -pub fn save_validated_b64_file( - b64data: &str, - output_dir: &Path, - media_type_prefix: &str, -) -> Result<(String, String), UploadError> { - let data = base64::decode(b64data)?; - if data.len() > UPLOAD_MAX_SIZE { - return Err(UploadError::TooLarge); - }; - let media_type = sniff_media_type(&data) - .ok_or(UploadError::InvalidMediaType)?; - if !media_type.starts_with(media_type_prefix) { - return Err(UploadError::InvalidMediaType); - }; - let file_name = save_file(data, output_dir, Some(&media_type))?; - Ok((file_name, media_type)) -}