From 888f9864653a63b4562a4b025e6c5676bd6e340d Mon Sep 17 00:00:00 2001 From: Maxime Levillain Date: Wed, 4 Jun 2025 09:27:12 +0200 Subject: [PATCH] feedback --- Makefile | 1 + interface/api/api.ml | 19 +++- interface/common/i.ml | 4 +- interface/common/serv.ml | 2 +- interface/ui/error.html | 9 +- interface/ui/index.html | 171 ++++++++++++++++----------------- interface/ui/notarization.html | 2 +- interface/ui/ui.ml | 166 ++++++++++++++++++++------------ 8 files changed, 211 insertions(+), 163 deletions(-) diff --git a/Makefile b/Makefile index 82d5828..de87069 100644 --- a/Makefile +++ b/Makefile @@ -52,6 +52,7 @@ check: clean: @rm -f pandora.wasm pandora_debug.wasm @cargo clean + @dune clean format-ocaml: @dune build @fmt --auto-promote --display=quiet 2> /dev/null || exit 0 diff --git a/interface/api/api.ml b/interface/api/api.ml index c3e2b1b..15b8508 100644 --- a/interface/api/api.ml +++ b/interface/api/api.ml @@ -34,9 +34,21 @@ let connect [%req] () = let notarize [%req] (n: notarization) = let>? account, _ = auth req in - let>? () = Serv.Proxy.(wrap @@ post_notarize ~input:n.hash !proxy) in - let>? status = Serv.Proxy.(wrap @@ post_status ~input:n.hash !proxy) in - Db.register_notarization ~account {n with status} + let> r = Db.notarization n.hash in + match r with + | Ok { status = Some _; _ } -> rok None + | Ok n -> + let>? status = Serv.Proxy.(wrap @@ post_status ~input:n.hash !proxy) in + let n = {n with status} in + let>? _ = Db.register_notarization n in + rok None + | Error NotFound _ -> + let>? () = Serv.Proxy.(wrap @@ post_notarize ~input:n.hash !proxy) in + let>? status = Serv.Proxy.(wrap @@ post_status ~input:n.hash !proxy) in + let n = { n with status } in + let>? id = Db.register_notarization ~account n in + rok (Some id) + | Error e -> rerr e [@@service Serv.Api.notarize] let get_account_param req = @@ -92,7 +104,6 @@ let verify_proof [%req] input = [@@service Serv.Api.verify_proof] - let openapi () = rok (snd @@ EzOpenAPI.make ~pretty:true ~sections:Serv.sections ~title:"Pandora App API" "") [@@service Serv.Api.openapi] diff --git a/interface/common/i.ml b/interface/common/i.ml index 19bd216..e83cabb 100644 --- a/interface/common/i.ml +++ b/interface/common/i.ml @@ -53,7 +53,8 @@ type error += | ServerError of server_error [@encoding server_error_enc] [@nowrap] | BadGateway of bad_gateway [@code 502] [@nowrap] | InvalidProof of string [@code 422] -[@@deriving err_case {code=500}] + | UiError of string list +[@@deriving err_case {code=500; debug}] let error_enc = Json_encoding.union (List.map snd !_error_cases_error) [@@@jsoo @@ -158,6 +159,7 @@ let pp_error fmt = function | ServerError DestructError s -> Format.fprintf fmt "destruct error: %s" s | ServerError Exn exn -> Format.fprintf fmt "exception: %s" (Printexc.to_string exn) | ServerError PsqlError {msg; _} -> Format.fprintf fmt "psql error: %s" msg + | UiError l -> Format.fprintf fmt "ui error: %s" @@ String.concat "\n" l | _ -> Format.fprintf fmt "unknown error" let print_error e = Format.eprintf "%a@." pp_error e diff --git a/interface/common/serv.ml b/interface/common/serv.ml index 4d167a6..2f851fc 100644 --- a/interface/common/serv.ml +++ b/interface/common/serv.ml @@ -56,7 +56,7 @@ module Api = struct | Ok x -> Ok x) p let%get connect = { path = "/connect"; errors; security; section=notarization_section } let%put notarize = { - path = "/notarization"; input=notarization_enc; output=int53; + path = "/notarization"; input=notarization_enc; output=(option int53); errors; security; section=notarization_section } let%get notarization = { path = "/notarization/{arg_hash}"; output=notarization_enc; diff --git a/interface/ui/error.html b/interface/ui/error.html index 694106b..1ffaaa5 100644 --- a/interface/ui/error.html +++ b/interface/ui/error.html @@ -2,19 +2,24 @@
- Error + Error +
- Unknown hash: + Hash not notarized:
Proxy error: {{ error.bad_gateway }}
+
+
Interface error:
+
{{ e }}
+
{{ error }}
diff --git a/interface/ui/index.html b/interface/ui/index.html index d0dd0b8..7f1b149 100644 --- a/interface/ui/index.html +++ b/interface/ui/index.html @@ -16,15 +16,12 @@