(* 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_extension = "txt" let is_valid_filename, media_to_extension = 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") ] in (* <> than the actual set of "supported" extension (which depends on config files) *) let all_known_extensions = mimetype_ext_assoc |> List.split |> snd in let is_valid_filename path = Fpath.mem_ext all_known_extensions path in let media_to_extension = function | Cohttp.Accept.MediaType (m, m_sub) -> List.assoc_opt (m, m_sub) mimetype_ext_assoc | AnyMediaSubtype m -> List.find_map (fun ((m', _), ext) -> match String.equal m m' with false -> None | true -> Some ext) mimetype_ext_assoc | AnyMedia -> Some default_extension in (is_valid_filename, media_to_extension)