rm config.ml
This commit is contained in:
parent
543c947da8
commit
bcd36c870b
6 changed files with 71 additions and 66 deletions
|
|
@ -7,7 +7,59 @@
|
|||
(* docs: https://docs.taler.net/manpages/taler-exchange.conf.5.html
|
||||
https://docs.taler.net/design-documents/003-tos-rendering.html *)
|
||||
|
||||
(* todo: maybe move this type to config.ml *)
|
||||
(* hardcoded config just for static assets *)
|
||||
module Config = struct
|
||||
let default_lang = "en"
|
||||
let default_encoding : [< `Identity | `DEFLATE | `Gzip ] = `Identity
|
||||
|
||||
(* 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 terms_dir = Fpath.(v "terms")
|
||||
let privacy_dir = Fpath.(v "privacy")
|
||||
|
||||
(* ETAG is used as base filename it should be encoded in Crockford base-32 we do
|
||||
not generate it and we do not verify it *)
|
||||
let terms_etag = "0" |> Headers_lib.Etag.of_crockford32 |> Result.get_ok
|
||||
let privacy_etag = "0" |> Headers_lib.Etag.of_crockford32 |> Result.get_ok
|
||||
let terms_legal_version = "1"
|
||||
let privacy_legal_version = "1"
|
||||
end
|
||||
|
||||
module Mimetype = struct
|
||||
let mimetype_extension_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");
|
||||
]
|
||||
|
||||
let mimetype_l, _ = List.split mimetype_extension_assoc
|
||||
|
||||
let of_cohttp_media = function
|
||||
| Cohttp.Accept.MediaType (m, m_sub) ->
|
||||
List.find_opt (( = ) (m, m_sub)) mimetype_l
|
||||
| AnyMediaSubtype m ->
|
||||
List.find_opt (fun (m', _) -> String.equal m m') mimetype_l
|
||||
| AnyMedia -> Some Config.default_mimetype
|
||||
|
||||
let to_extension (m, m_sub) =
|
||||
assert (m <> "*");
|
||||
assert (m_sub <> "*");
|
||||
List.assoc_opt (m, m_sub) mimetype_extension_assoc
|
||||
|
||||
let of_extension ext =
|
||||
List.find_map
|
||||
(fun (mime, ext') ->
|
||||
match String.equal ext ext' with false -> None | true -> Some mime)
|
||||
mimetype_extension_assoc
|
||||
|
||||
let pp_mime fmt mime = Fmt.pf fmt "%s/%s" (fst mime) (snd mime)
|
||||
end
|
||||
|
||||
type t =
|
||||
| Terms
|
||||
| Privacy
|
||||
|
|
@ -88,7 +140,7 @@ let supported_lang_arr, supported_ext_arr =
|
|||
(Array.of_list lang_l, Array.of_list ext_l)
|
||||
|
||||
let supported_mimetype_arr =
|
||||
Array.map Util.Mimetype.of_extension supported_ext_arr |> Array.map Option.get
|
||||
Array.map Mimetype.of_extension supported_ext_arr |> Array.map Option.get
|
||||
|
||||
let is_supported_lang lang = Array.mem lang supported_lang_arr
|
||||
let is_supported_ext ext = Array.mem ext supported_ext_arr
|
||||
|
|
@ -101,7 +153,7 @@ let is_supported_mimetype mime = Array.mem mime supported_mimetype_arr
|
|||
let get_content ~lang ~mime t =
|
||||
let etag = Headers_lib.Etag.to_raw_string (etag t) in
|
||||
let ext =
|
||||
match Util.Mimetype.to_extension mime with
|
||||
match Mimetype.to_extension mime with
|
||||
| None -> Fmt.failwith "mimetype `%s/%s` unknown" (fst mime) (snd mime)
|
||||
| Some ext -> ext
|
||||
in
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue