improved file type detection
This commit is contained in:
Generated
+1
@@ -893,6 +893,7 @@ dependencies = [
|
|||||||
"http-body-util",
|
"http-body-util",
|
||||||
"infer",
|
"infer",
|
||||||
"jsonwebtoken",
|
"jsonwebtoken",
|
||||||
|
"mime_guess",
|
||||||
"password-hash",
|
"password-hash",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"serde",
|
"serde",
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ clap = { version = "4.5.53", features = ["derive"] }
|
|||||||
dashmap = "6.1.0"
|
dashmap = "6.1.0"
|
||||||
infer = "0.19.0"
|
infer = "0.19.0"
|
||||||
jsonwebtoken = "9.3.1"
|
jsonwebtoken = "9.3.1"
|
||||||
|
mime_guess = "2.0.5"
|
||||||
password-hash = "0.5.0"
|
password-hash = "0.5.0"
|
||||||
serde = { version = "1.0.219", features = ["derive"] }
|
serde = { version = "1.0.219", features = ["derive"] }
|
||||||
serde_json = "1.0.143"
|
serde_json = "1.0.143"
|
||||||
|
|||||||
@@ -406,17 +406,21 @@ async fn create_message_with_attachments(
|
|||||||
return Err(APIError::FileTooLarge);
|
return Err(APIError::FileTooLarge);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine file type
|
let mut mime = mime_guess::from_path(&file_name)
|
||||||
let kind = infer::get(&data);
|
.first_raw()
|
||||||
let mime = kind
|
|
||||||
.map(|k| k.mime_type())
|
|
||||||
.unwrap_or("application/octet-stream");
|
.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/") {
|
let file_type = if mime.starts_with("image/") {
|
||||||
"image"
|
"image"
|
||||||
} else if mime.starts_with("video/") {
|
} else if mime.starts_with("video/") {
|
||||||
"video"
|
"video"
|
||||||
} else if mime.starts_with("text/") {
|
} else if mime.starts_with("text/") || std::str::from_utf8(&data).is_ok() {
|
||||||
"textfile"
|
"textfile"
|
||||||
} else {
|
} else {
|
||||||
"binaryfile"
|
"binaryfile"
|
||||||
|
|||||||
Reference in New Issue
Block a user