rm headers_lib

This commit is contained in:
swrup 2026-03-20 01:13:21 +01:00 committed by Swrup
parent 75759afe69
commit 4e707b080a
7 changed files with 29 additions and 149 deletions

View file

@ -1,12 +1,11 @@
(* https://docs.taler.net/design-documents/003-tos-rendering.html
must support `text/plain` and `text/markdown` *)
type t =
| Terms
| Privacy
module Assets_config = struct
module Cfg = struct
(* hardcoded config just for static assets *)
let default_lang = "en"
let default_mimetype = ("text", "plain")
@ -23,7 +22,7 @@ let etag k =
let supported_lang_arr, supported_ext_arr =
let aux t =
let prefix = Fpath.v (Assets_config.base_dir t) in
let prefix = Fpath.v (Cfg.base_dir t) in
let path_l = List.map Fpath.v Assets_crunch.file_list in
let path_l = List.filter_map (Fpath.rem_prefix prefix) path_l in
let ext_l =
@ -41,21 +40,20 @@ let supported_lang_arr, supported_ext_arr =
path_l
in
let lang_l = List.sort_uniq String.compare lang_l in
let etag = (etag t).value in
let etag = etag t in
List.iter
(fun path ->
let etag' = Fpath.to_string (Fpath.rem_ext (Fpath.base path)) in
if not @@ String.equal etag etag' then
Fmt.failwith
"filename of file `%s` does not match configuration ETAG value `%s`"
"filename `%s` does not match configuration ETAG value `%s`"
(Fpath.to_string Fpath.(prefix // path))
etag)
path_l;
if List.is_empty lang_l then Fmt.failwith "no language supported";
if List.is_empty ext_l then Fmt.failwith "no mimetype supported";
if not @@ List.mem Assets_config.default_lang lang_l then
Fmt.failwith "default language `%s` files not found"
Assets_config.default_lang;
if not @@ List.mem Cfg.default_lang lang_l then
Fmt.failwith "default language `%s` files not found" Cfg.default_lang;
if not @@ List.mem ".txt" ext_l then
Fmt.failwith "plain text file not found";
if not @@ List.mem ".md" ext_l then Fmt.failwith "markdown file not found";
@ -102,6 +100,13 @@ module Mimetype = struct
(("image", "gif"), ".gif");
]
let default = Cfg.default_mimetype
let () =
if not @@ List.mem (Cfg.default_mimetype, Cfg.default_extension) assoc then
Fmt.failwith "default content type `%a` not supported" pp
Cfg.default_mimetype
let arr =
let all_supported, all_supported_ext = List.split assoc in
match
@ -112,17 +117,6 @@ module Mimetype = struct
| Some ext -> Fmt.failwith "extension `%s` unsupported" ext
| None -> Array.of_list all_supported
let default =
match
List.mem
(Assets_config.default_mimetype, Assets_config.default_extension)
assoc
with
| false ->
Fmt.failwith "default content type `%a` not supported" pp
Assets_config.default_mimetype
| true -> Assets_config.default_mimetype
let of_cohttp = function
| Cohttp.Accept.MediaType (m, m_sub) ->
Array.find_opt (( = ) (m, m_sub)) arr
@ -139,7 +133,11 @@ module Language = struct
type t = string
let arr = supported_lang_arr
let default = Assets_config.default_lang
let default = Cfg.default_lang
let () =
if not @@ Array.mem default arr then
Fmt.failwith "default language `%s` not supported" Cfg.default_lang
let of_cohttp = function
| Cohttp.Accept.AnyLanguage -> Some default
@ -155,8 +153,7 @@ end
let get_content ~lang ~mime t =
let ext = Mimetype.to_extension_exn mime in
let path =
Fpath.to_string
Fpath.((v (Assets_config.base_dir t) / lang / (etag t).value) + ext)
Fpath.to_string Fpath.((v (Cfg.base_dir t) / lang / etag t) + ext)
in
match Assets_crunch.read path with
| None -> Fmt.failwith "static file not found: `%s`" path