add assets.ml

This commit is contained in:
Swrup 2025-09-23 20:58:34 +02:00
parent 2eb42f51cc
commit 2828e171aa
11 changed files with 212 additions and 169 deletions

29
src/util.ml Normal file
View file

@ -0,0 +1,29 @@
(* 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 (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)