Remove save_validated_b64_file() function

This commit is contained in:
silverpill 2023-01-06 15:29:50 +00:00
parent 7539533b69
commit 7a4be5dd5a
2 changed files with 6 additions and 21 deletions

View file

@ -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)
}

View file

@ -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))
}