summaryrefslogtreecommitdiff
path: root/lib/handlers.ml
blob: 27ca0b6816d7f08ac03034842e95c5697f1d86b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
let ogit_root _req = Views.ogit_root () |> Dream_html.respond

let repo_summary req =
  let repo_path = Dream.param req "repo_name" in
  let%lwt branches_result = Git_helpers.all_branches repo_path in
  let%lwt commits_result = Git_helpers.latest_commits repo_path 10 in
  match (branches_result, commits_result) 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 repo_tree req = *)
(*   let repo_name = Dream.param req "repo_name" in *)
(*   let path = Git_helpers.full_path repo_name in *)
(*   let dir_path = Dream.target req in *)
(*   Views.repo_tree ~repo_path:path dir_path |> Dream_html.respond *)

(* let repo_blob req = *)
(*   let repo_name = Dream.param req "repo_name" in *)
(*   let path = Git_helpers.full_path repo_name in *)
(*   let blob_path = Dream.query req "path" |> Option.value ~default:"" in *)
(*   Views.repo_blob repo_name blob_path |> Dream_html.respond *)

let all_handlers =
  [
    Dream.get "/" ogit_root;
    Dream.scope "/:repo_name" []
      [
        Dream.get "/" repo_summary;
        (* Dream.get "/tree" repo_tree; *)
        (* Dream.get "/blob" repo_blob; *)
      ];
    Dream.get "/static/**" (Dream.static "./lib/static");
  ]
Copyright 2019--2025 Marius PETER