improved file type detection

This commit is contained in:
2026-06-28 18:51:05 +02:00
parent b45f5ff35f
commit 5175d585fc
3 changed files with 11 additions and 5 deletions
Generated
+1
View File
@@ -893,6 +893,7 @@ dependencies = [
"http-body-util",
"infer",
"jsonwebtoken",
"mime_guess",
"password-hash",
"reqwest",
"serde",
+1
View File
@@ -14,6 +14,7 @@ clap = { version = "4.5.53", features = ["derive"] }
dashmap = "6.1.0"
infer = "0.19.0"
jsonwebtoken = "9.3.1"
mime_guess = "2.0.5"
password-hash = "0.5.0"
serde = { version = "1.0.219", features = ["derive"] }
serde_json = "1.0.143"
+9 -5
View File
@@ -406,17 +406,21 @@ async fn create_message_with_attachments(
return Err(APIError::FileTooLarge);
}
// Determine file type
let kind = infer::get(&data);
let mime = kind
.map(|k| k.mime_type())
let mut mime = mime_guess::from_path(&file_name)
.first_raw()
.unwrap_or("application/octet-stream");
if mime == "application/octet-stream" {
if let Some(kind) = infer::get(&data) {
mime = kind.mime_type();
}
}
let file_type = if mime.starts_with("image/") {
"image"
} else if mime.starts_with("video/") {
"video"
} else if mime.starts_with("text/") {
} else if mime.starts_with("text/") || std::str::from_utf8(&data).is_ok() {
"textfile"
} else {
"binaryfile"