1mod image;
6mod mime;
7mod pdf;
8mod svg;
9
10pub use image::*;
11pub use mime::*;
12pub use pdf::*;
13pub use svg::*;
14
15pub use image::estimate_image_dimensions;
17pub use image::read_image_file_enhanced;
18
19use std::path::Path;
20
21#[derive(Debug, Clone, Copy, PartialEq, Eq)]
23pub enum MediaType {
24 Image,
25 Pdf,
26 Svg,
27 Unknown,
28}
29
30#[derive(Debug, Clone)]
32pub enum MediaResult {
33 Image(ImageResult),
34 Pdf(PdfReadResult),
35}
36
37pub fn detect_media_type(file_path: &Path) -> MediaType {
39 let ext = file_path
40 .extension()
41 .and_then(|e| e.to_str())
42 .unwrap_or("")
43 .to_lowercase();
44
45 if is_supported_image_format(&ext) {
46 return MediaType::Image;
47 }
48
49 if is_pdf_extension(&ext) {
50 return MediaType::Pdf;
51 }
52
53 if ext == "svg" {
54 return MediaType::Svg;
55 }
56
57 MediaType::Unknown
58}
59
60pub fn is_supported_media_file(file_path: &Path) -> bool {
62 detect_media_type(file_path) != MediaType::Unknown
63}
64
65pub static BINARY_FILE_BLACKLIST: &[&str] = &[
68 "mp3", "wav", "flac", "ogg", "aac", "m4a", "wma", "aiff", "opus", "mp4", "avi", "mov", "wmv", "flv", "mkv", "webm", "m4v", "mpeg", "mpg",
71 "zip", "rar", "tar", "gz", "bz2", "7z", "xz", "z", "tgz", "iso", "exe", "dll", "so", "dylib", "app", "msi", "deb", "rpm", "bin", "dat", "db", "sqlite", "sqlite3", "mdb", "idx", "doc", "docx", "xls", "xlsx", "ppt", "pptx", "odt", "ods", "odp", "ttf", "otf", "woff", "woff2", "eot", "psd", "ai", "eps", "sketch", "fig", "xd", "blend", "obj", "3ds", "max",
78 "class", "jar", "war", "pyc", "pyo", "rlib", "swf", "fla",
80];
81
82pub fn is_blacklisted_file(file_path: &Path) -> bool {
84 let ext = file_path
85 .extension()
86 .and_then(|e| e.to_str())
87 .unwrap_or("")
88 .to_lowercase();
89
90 BINARY_FILE_BLACKLIST.contains(&ext.as_str())
91}
92
93#[cfg(test)]
94mod tests;