(* TODO Taler documentation markdown mimetype should be the prefered one, and be supported, according to DD we take text/plain as default instead for now *) let default_mimetype = ("text", "plain") let default_extension = "txt" let mimetype_ext_assoc = [ (("text", "plain"), "txt"); (("text", "markdown"), "md") ; (("text", "html"), "html"); (("text", "html"), "htm") ; (("application", "pdf"), "pdf"); (("image", "jpeg"), "jpg") ; (("image", "jpeg"), "jpeg"); (("image", "png"), "png") ; (("image", "gif"), "gif") ] (* <> than the actual set of "supported" extension (which depends on config files) *) let all_known_mimetypes, all_known_extensions = List.split mimetype_ext_assoc let is_valid_filename path = Fpath.mem_ext all_known_extensions path let media_to_known_mimetype = function | Cohttp.Accept.MediaType (m, m_sub) -> List.find_opt (( = ) (m, m_sub)) all_known_mimetypes | AnyMediaSubtype m -> List.find_opt (fun (m', _) -> String.equal m m') all_known_mimetypes | AnyMedia -> Some default_mimetype let mimetype_to_extension (m, m_sub) = assert (m <> "*"); assert (m_sub <> "*"); List.assoc_opt (m, m_sub) mimetype_ext_assoc let extension_to_mimetype ext = List.find_map (fun (mime, ext') -> match String.equal ext ext' with false -> None | true -> Some mime) mimetype_ext_assoc