Don't treat SVG files as images

This commit is contained in:
silverpill 2022-12-22 21:42:14 +00:00
parent 7b69dc9219
commit 209f520d28
2 changed files with 7 additions and 3 deletions

View file

@ -19,7 +19,7 @@ async fn create_attachment_view(
) -> Result<HttpResponse, HttpError> {
let db_client = &**get_database_client(&db_pool).await?;
let current_user = get_current_user(db_client, auth.token()).await?;
let (file_name, media_type) = save_b64_file(
let (file_name, maybe_media_type) = save_b64_file(
&attachment_data.file,
attachment_data.media_type.clone(),
&config.media_dir(),
@ -28,7 +28,7 @@ async fn create_attachment_view(
db_client,
&current_user.id,
file_name,
media_type,
maybe_media_type,
).await?;
let attachment = Attachment::from_db(
db_attachment,

View file

@ -33,13 +33,17 @@ impl From<UploadError> for HttpError {
pub fn save_b64_file(
b64data: &str,
maybe_media_type: Option<String>,
mut maybe_media_type: Option<String>,
output_dir: &Path,
) -> Result<(String, Option<String>), UploadError> {
let data = base64::decode(b64data)?;
if data.len() > UPLOAD_MAX_SIZE {
return Err(UploadError::TooLarge);
};
if maybe_media_type.as_deref() == Some("image/svg+xml") {
// Don't treat SVG files as images
maybe_media_type = None;
};
Ok(save_file(data, output_dir, maybe_media_type)?)
}