Skip to content
This repository was archived by the owner on Dec 19, 2024. It is now read-only.

Commit d521872

Browse files
committed
feat: add support for apk, webp, wav, opus, ogg
closes #24 partially solves #5
1 parent f9a1058 commit d521872

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "autumn"
3-
version = "1.1.9"
3+
version = "1.1.10"
44
authors = ["Paul Makles <[email protected]>"]
55
edition = "2018"
66

src/routes/upload.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::config::{get_tag, Config, ContentType};
22
use crate::db::*;
33
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};
55

66
use actix_multipart::Multipart;
77
use actix_web::{web, HttpRequest, HttpResponse};
@@ -60,7 +60,23 @@ pub async fn post(req: HttpRequest, mut payload: Multipart) -> Result<HttpRespon
6060
}
6161

6262
// ? 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+
6480
let s = &content_type[..];
6581

6682
let metadata = match s {
@@ -123,7 +139,7 @@ pub async fn post(req: HttpRequest, mut payload: Multipart) -> Result<HttpRespon
123139
.map_err(|_| Error::IOError)?;
124140

125141
buf = bytes;
126-
142+
127143
// Calculate dimensions after rotation.
128144
let (width, height) = match &rotation {
129145
2 | 4 | 5 | 7 => (height, width),
@@ -196,7 +212,10 @@ pub async fn post(req: HttpRequest, mut payload: Multipart) -> Result<HttpRespon
196212
Metadata::File
197213
}
198214
}
199-
/* mp3 */ "audio/mpeg" => {
215+
/* mp3 */ "audio/mpeg" |
216+
/* wav */ "audio/wav" |
217+
/* ogg */ "audio/x-vorbis+ogg" |
218+
/* opus */ "audio/x-opus+ogg" => {
200219
Metadata::Audio
201220
}
202221
_ => {

0 commit comments

Comments
 (0)