|
1 | 1 | use crate::config::{get_tag, Config, ContentType};
|
2 | 2 | use crate::db::*;
|
3 | 3 | use crate::util::result::Error;
|
4 |
| -use crate::util::variables::{get_s3_bucket, LOCAL_STORAGE_PATH, USE_S3, USE_CLAMD, CLAMD_HOST}; |
| 4 | +use crate::util::variables::{get_s3_bucket, CLAMD_HOST, LOCAL_STORAGE_PATH, USE_CLAMD, USE_S3}; |
5 | 5 |
|
6 | 6 | use actix_multipart::Multipart;
|
7 | 7 | use actix_web::{web, HttpRequest, HttpResponse};
|
@@ -60,7 +60,23 @@ pub async fn post(req: HttpRequest, mut payload: Multipart) -> Result<HttpRespon
|
60 | 60 | }
|
61 | 61 |
|
62 | 62 | // ? Find the content-type of the data.
|
63 |
| - let content_type = tree_magic::from_u8(&buf); |
| 63 | + let mut content_type = tree_magic::from_u8(&buf); |
| 64 | + |
| 65 | + // Intercept known file extensions with certain content types |
| 66 | + if content_type == "application/zip" && filename.to_lowercase().ends_with(".apk") { |
| 67 | + content_type = "application/vnd.android.package-archive".to_string(); |
| 68 | + } |
| 69 | + |
| 70 | + if content_type == "application/x-riff" { |
| 71 | + if filename.to_lowercase().ends_with(".webp") { |
| 72 | + content_type = "image/webp".to_string(); |
| 73 | + } else if filename.to_lowercase().ends_with(".wav") |
| 74 | + || filename.to_lowercase().ends_with(".wave") |
| 75 | + { |
| 76 | + content_type = "audio/wav".to_string(); |
| 77 | + } |
| 78 | + } |
| 79 | + |
64 | 80 | let s = &content_type[..];
|
65 | 81 |
|
66 | 82 | let metadata = match s {
|
@@ -123,7 +139,7 @@ pub async fn post(req: HttpRequest, mut payload: Multipart) -> Result<HttpRespon
|
123 | 139 | .map_err(|_| Error::IOError)?;
|
124 | 140 |
|
125 | 141 | buf = bytes;
|
126 |
| - |
| 142 | + |
127 | 143 | // Calculate dimensions after rotation.
|
128 | 144 | let (width, height) = match &rotation {
|
129 | 145 | 2 | 4 | 5 | 7 => (height, width),
|
@@ -196,7 +212,10 @@ pub async fn post(req: HttpRequest, mut payload: Multipart) -> Result<HttpRespon
|
196 | 212 | Metadata::File
|
197 | 213 | }
|
198 | 214 | }
|
199 |
| - /* mp3 */ "audio/mpeg" => { |
| 215 | + /* mp3 */ "audio/mpeg" | |
| 216 | + /* wav */ "audio/wav" | |
| 217 | + /* ogg */ "audio/x-vorbis+ogg" | |
| 218 | + /* opus */ "audio/x-opus+ogg" => { |
200 | 219 | Metadata::Audio
|
201 | 220 | }
|
202 | 221 | _ => {
|
|
0 commit comments