Don't treat SVG files as images
This commit is contained in:
parent
7b69dc9219
commit
209f520d28
2 changed files with 7 additions and 3 deletions
|
@ -19,7 +19,7 @@ async fn create_attachment_view(
|
||||||
) -> Result<HttpResponse, HttpError> {
|
) -> Result<HttpResponse, HttpError> {
|
||||||
let db_client = &**get_database_client(&db_pool).await?;
|
let db_client = &**get_database_client(&db_pool).await?;
|
||||||
let current_user = get_current_user(db_client, auth.token()).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.file,
|
||||||
attachment_data.media_type.clone(),
|
attachment_data.media_type.clone(),
|
||||||
&config.media_dir(),
|
&config.media_dir(),
|
||||||
|
@ -28,7 +28,7 @@ async fn create_attachment_view(
|
||||||
db_client,
|
db_client,
|
||||||
¤t_user.id,
|
¤t_user.id,
|
||||||
file_name,
|
file_name,
|
||||||
media_type,
|
maybe_media_type,
|
||||||
).await?;
|
).await?;
|
||||||
let attachment = Attachment::from_db(
|
let attachment = Attachment::from_db(
|
||||||
db_attachment,
|
db_attachment,
|
||||||
|
|
|
@ -33,13 +33,17 @@ impl From<UploadError> for HttpError {
|
||||||
|
|
||||||
pub fn save_b64_file(
|
pub fn save_b64_file(
|
||||||
b64data: &str,
|
b64data: &str,
|
||||||
maybe_media_type: Option<String>,
|
mut maybe_media_type: Option<String>,
|
||||||
output_dir: &Path,
|
output_dir: &Path,
|
||||||
) -> Result<(String, Option<String>), UploadError> {
|
) -> Result<(String, Option<String>), UploadError> {
|
||||||
let data = base64::decode(b64data)?;
|
let data = base64::decode(b64data)?;
|
||||||
if data.len() > UPLOAD_MAX_SIZE {
|
if data.len() > UPLOAD_MAX_SIZE {
|
||||||
return Err(UploadError::TooLarge);
|
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)?)
|
Ok(save_file(data, output_dir, maybe_media_type)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue