improved file type detection
This commit is contained in:
Generated
+1
@@ -893,6 +893,7 @@ dependencies = [
|
||||
"http-body-util",
|
||||
"infer",
|
||||
"jsonwebtoken",
|
||||
"mime_guess",
|
||||
"password-hash",
|
||||
"reqwest",
|
||||
"serde",
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user