88//! However, postgres is still available for testing and backwards compatibility.
99
1010use crate :: error:: Result ;
11- use crate :: {
12- db:: mimes,
13- storage:: { AsyncStorage , CompressionAlgorithm } ,
14- } ;
11+ use crate :: storage:: { AsyncStorage , CompressionAlgorithm } ;
12+ use docs_rs_mimes:: detect_mime;
1513use mime:: Mime ;
1614use serde_json:: Value ;
17- use std:: ffi:: OsStr ;
1815use std:: path:: { Path , PathBuf } ;
1916use tracing:: instrument;
2017
@@ -32,32 +29,6 @@ impl FileEntry {
3229 }
3330}
3431
35- pub ( crate ) fn detect_mime ( file_path : impl AsRef < Path > ) -> Mime {
36- let mime = mime_guess:: from_path ( file_path. as_ref ( ) )
37- . first ( )
38- . unwrap_or ( mime:: TEXT_PLAIN ) ;
39-
40- match mime. as_ref ( ) {
41- "text/plain" | "text/troff" | "text/x-markdown" | "text/x-rust" | "text/x-toml" => {
42- match file_path. as_ref ( ) . extension ( ) . and_then ( OsStr :: to_str) {
43- Some ( "md" ) => mimes:: TEXT_MARKDOWN . clone ( ) ,
44- Some ( "rs" ) => mimes:: TEXT_RUST . clone ( ) ,
45- Some ( "markdown" ) => mimes:: TEXT_MARKDOWN . clone ( ) ,
46- Some ( "css" ) => mime:: TEXT_CSS ,
47- Some ( "toml" ) => mimes:: TEXT_TOML . clone ( ) ,
48- Some ( "js" ) => mime:: TEXT_JAVASCRIPT ,
49- Some ( "json" ) => mime:: APPLICATION_JSON ,
50- Some ( "gz" ) => mimes:: APPLICATION_GZIP . clone ( ) ,
51- Some ( "zst" ) => mimes:: APPLICATION_ZSTD . clone ( ) ,
52- _ => mime,
53- }
54- }
55- "image/svg" => mime:: IMAGE_SVG ,
56-
57- _ => mime,
58- }
59- }
60-
6132/// Store all files in a directory and return [[mimetype, filename]] as Json
6233///
6334/// If there is an S3 Client configured, store files into an S3 bucket;
@@ -101,27 +72,3 @@ pub(crate) fn file_list_to_json(files: impl IntoIterator<Item = FileEntry>) -> V
10172 . collect ( ) ,
10273 )
10374}
104-
105- #[ cfg( test) ]
106- mod tests {
107- use super :: * ;
108- use test_case:: test_case;
109-
110- // some standard mime types that mime-guess handles
111- #[ test_case( "txt" , & mime:: TEXT_PLAIN ) ]
112- #[ test_case( "html" , & mime:: TEXT_HTML ) ]
113- // overrides of other mime types and defaults for
114- // types mime-guess doesn't know about
115- #[ test_case( "md" , & mimes:: TEXT_MARKDOWN ) ]
116- #[ test_case( "rs" , & mimes:: TEXT_RUST ) ]
117- #[ test_case( "markdown" , & mimes:: TEXT_MARKDOWN ) ]
118- #[ test_case( "css" , & mime:: TEXT_CSS ) ]
119- #[ test_case( "toml" , & mimes:: TEXT_TOML ) ]
120- #[ test_case( "js" , & mime:: TEXT_JAVASCRIPT ) ]
121- #[ test_case( "json" , & mime:: APPLICATION_JSON ) ]
122- #[ test_case( "zst" , & mimes:: APPLICATION_ZSTD ) ]
123- #[ test_case( "gz" , & mimes:: APPLICATION_GZIP ) ]
124- fn test_detect_mime ( ext : & str , expected : & Mime ) {
125- assert_eq ! ( & detect_mime( format!( "something.{ext}" ) ) , expected) ;
126- }
127- }
0 commit comments