Skip to content

Commit

Permalink
feat: add support for apk, webp, wav, opus, ogg
Browse files Browse the repository at this point in the history
closes #24
partially solves #5
  • Loading branch information
insertish committed Jun 7, 2023
1 parent f9a1058 commit d521872
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "autumn"
version = "1.1.9"
version = "1.1.10"
authors = ["Paul Makles <[email protected]>"]
edition = "2018"

Expand Down
27 changes: 23 additions & 4 deletions src/routes/upload.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::config::{get_tag, Config, ContentType};
use crate::db::*;
use crate::util::result::Error;
use crate::util::variables::{get_s3_bucket, LOCAL_STORAGE_PATH, USE_S3, USE_CLAMD, CLAMD_HOST};
use crate::util::variables::{get_s3_bucket, CLAMD_HOST, LOCAL_STORAGE_PATH, USE_CLAMD, USE_S3};

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

// ? Find the content-type of the data.
let content_type = tree_magic::from_u8(&buf);
let mut content_type = tree_magic::from_u8(&buf);

// Intercept known file extensions with certain content types
if content_type == "application/zip" && filename.to_lowercase().ends_with(".apk") {
content_type = "application/vnd.android.package-archive".to_string();
}

if content_type == "application/x-riff" {
if filename.to_lowercase().ends_with(".webp") {
content_type = "image/webp".to_string();
} else if filename.to_lowercase().ends_with(".wav")
|| filename.to_lowercase().ends_with(".wave")
{
content_type = "audio/wav".to_string();
}
}

let s = &content_type[..];

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

buf = bytes;

// Calculate dimensions after rotation.
let (width, height) = match &rotation {
2 | 4 | 5 | 7 => (height, width),
Expand Down Expand Up @@ -196,7 +212,10 @@ pub async fn post(req: HttpRequest, mut payload: Multipart) -> Result<HttpRespon
Metadata::File
}
}
/* mp3 */ "audio/mpeg" => {
/* mp3 */ "audio/mpeg" |
/* wav */ "audio/wav" |
/* ogg */ "audio/x-vorbis+ogg" |
/* opus */ "audio/x-opus+ogg" => {
Metadata::Audio
}
_ => {
Expand Down

0 comments on commit d521872

Please sign in to comment.