pub fn media_type(file_path: &str) -> Option<&'static str> {
std::path::Path::new(file_path)
.extension()
.and_then(std::ffi::OsStr::to_str)
.map(ext_to_mime)
.unwrap_or_default()
}
fn ext_to_mime(ext: &str) -> Option<&'static str> {
match ext {
"html" => Some(mime::TEXT_HTML_UTF_8.as_ref()),
"css" => Some(mime::TEXT_CSS.as_ref()),
"js" | "ts" => Some(mime::TEXT_JAVASCRIPT.as_ref()),
"jpg" | "jpeg" => Some(mime::IMAGE_JPEG.as_ref()),
"png" => Some(mime::IMAGE_PNG.as_ref()),
"gif" => Some(mime::IMAGE_GIF.as_ref()),
"toml" => Some("application/toml"),
"yaml" | "yml" => Some("text/x-yaml"),
"json" => Some(mime::APPLICATION_JSON.as_ref()),
"txt" | "py" | "rs" | "hbs" => Some(mime::TEXT_PLAIN.as_ref()),
"md" => Some("text/markdown"),
"wasm" => Some("application/wasm"),
"ico" => Some("image/vnd.microsoft.icon"),
"csv" => Some(mime::TEXT_CSV_UTF_8.as_ref()),
"pdf" => Some(mime::APPLICATION_PDF.as_ref()),
"bin" | "enc" | "dat" | "gz" | "tar" | "z" => Some(mime::APPLICATION_OCTET_STREAM.as_ref()),
_ => None,
}
}