diff options
author | Marius Peter <marius.peter@tutanota.com> | 2025-05-17 19:20:28 +0200 |
---|---|---|
committer | Marius Peter <marius.peter@tutanota.com> | 2025-05-17 19:20:28 +0200 |
commit | 59b321967f83385296c9ce92fb29ee7f6c8b75db (patch) | |
tree | 1d29f39dd51c501f7450b23a6aa5a852d6b03261 | |
parent | 2f57633bdf9f6d36a554cc4c9105e7c26f548f67 (diff) |
Added custom let* for handlers.
The error page is now displayed for any intermediate error.
-rw-r--r-- | lib/handlers.ml | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/lib/handlers.ml b/lib/handlers.ml index f4a7d7b..95aecd3 100644 --- a/lib/handlers.ml +++ b/lib/handlers.ml @@ -1,15 +1,24 @@ -open Lwt.Syntax +let ( let* ) m f = + let open Lwt.Infix in + m >>= function + | Ok x -> f x + | Error e -> + let msg = Format.asprintf "%a" Git_unix.Store.pp_error e in + Views.error_page msg |> Dream_html.respond let ogit_root _req = Views.ogit_root () |> Dream_html.respond let repo_summary req = let repo_path = Dream.param req "repo_name" in - let* branches = Git_helpers.all_branches repo_path - and* commits = Git_helpers.latest_commits repo_path 10 in - match (branches, commits) with - | Ok branches, Ok commits -> - Views.repo_summary repo_path ~branches ~commits |> Dream_html.respond - | Error msg, _ | _, Error msg -> Views.error_page msg |> Dream_html.respond + let branches = [ "bing"; "bong" ] in + let* commits = Git_helpers.recent_commits repo_path 10 in + Views.repo_summary repo_path branches commits |> Dream_html.respond + +let repo_commit req = + let repo_path = Dream.param req "repo_name" in + let id = match Dream.query req "id" with Some id -> id | None -> "" in + let* commit = Git_helpers.get_commit repo_path id in + Views.repo_commit repo_path commit |> Dream_html.respond (* let repo_tree req = *) (* let repo_name = Dream.param req "repo_name" in *) @@ -29,6 +38,7 @@ let all_handlers = Dream.scope "/:repo_name" [] [ Dream.get "/" repo_summary; + Dream.get "/commit/" repo_commit; (* Dream.get "/tree" repo_tree; *) (* Dream.get "/blob" repo_blob; *) ]; |