This commit is contained in:
parent
3f17260d53
commit
ef2aa1ddd7
1 changed files with 35 additions and 26 deletions
|
|
@ -1,4 +1,6 @@
|
|||
(* doc: https://docs.taler.net/design-documents/003-tos-rendering.html
|
||||
(* https://docs.taler.net/design-documents/003-tos-rendering.html
|
||||
https://docs.taler.net/design-documents/003-tos-rendering.html
|
||||
|
||||
must support `text/plain` and `text/markdown` *)
|
||||
|
||||
type t =
|
||||
|
|
@ -13,16 +15,15 @@ module Assets_config = struct
|
|||
let default_encoding : [< `Identity | `DEFLATE | `Gzip ] = `Identity
|
||||
let base_dir = function Terms -> "terms" | Privacy -> "privacy"
|
||||
|
||||
(* TODO
|
||||
how to update ToS version?
|
||||
where to get it? *)
|
||||
(* TODO this should be in the config like terms_etag *)
|
||||
let terms_legal_version = "0"
|
||||
let privacy_legal_version = "0"
|
||||
end
|
||||
|
||||
(* TODO etag = filename *)
|
||||
let etag k =
|
||||
let etag = match k with Terms -> "0" | Privacy -> "0" in
|
||||
let etag =
|
||||
match k with Terms -> Config.terms_etag | Privacy -> Config.privacy_etag
|
||||
in
|
||||
etag |> Headers_lib.Etag.of_crockford32 |> Result.get_ok
|
||||
|
||||
let legal_version = function
|
||||
|
|
@ -49,26 +50,34 @@ let supported_lang_arr, supported_ext_arr =
|
|||
path_l
|
||||
in
|
||||
let lang_l = List.sort_uniq String.compare lang_l in
|
||||
let () =
|
||||
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 ".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";
|
||||
List.iter
|
||||
(fun dir ->
|
||||
if String.length dir <> 2 then
|
||||
Fmt.failwith "language directory with invalid name: `%s`" dir)
|
||||
lang_l;
|
||||
if List.length path_l <> List.length ext_l * List.length lang_l then
|
||||
Fmt.failwith
|
||||
"invalid folder structure, all supported language must provide the \
|
||||
same set of file mimetype"
|
||||
in
|
||||
(lang_l, ext_l)
|
||||
let etag = Headers_lib.Etag.to_raw_string (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`"
|
||||
(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 ".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";
|
||||
List.iter
|
||||
(fun dir ->
|
||||
if String.length dir <> 2 then
|
||||
Fmt.failwith "language directory with invalid name: `%s`" dir)
|
||||
lang_l;
|
||||
if List.length path_l <> List.length ext_l * List.length lang_l then
|
||||
Fmt.failwith
|
||||
"invalid folder structure, all supported language must provide the \
|
||||
same set of file mimetype"
|
||||
else (lang_l, ext_l)
|
||||
in
|
||||
let lang_l, ext_l = aux Terms in
|
||||
let lang_l', ext_l' = aux Privacy in
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue