From 9e7f27c60a425e2baa67cd459d8509a43b1d123d Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Tue, 8 Aug 2023 10:40:52 +0200 Subject: Update to brr 0.0.6 --- lib/elements/transfert.ml | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) (limited to 'lib/elements/transfert.ml') diff --git a/lib/elements/transfert.ml b/lib/elements/transfert.ml index 878af2d..6eb85f9 100755 --- a/lib/elements/transfert.ml +++ b/lib/elements/transfert.ml @@ -11,7 +11,6 @@ let send_raw : filename:Jstr.t -> Jstr.t -> unit = in El.click a - (** Send a file to the user. *) let send : mime_type:Jstr.t -> filename:Jstr.t -> Jstr.t -> unit = fun ~mime_type ~filename content -> @@ -20,35 +19,30 @@ let send : mime_type:Jstr.t -> filename:Jstr.t -> Jstr.t -> unit = let data = Jv.to_jstr - @@ Jv.call - (Jv.of_string "data:") - "concat" + @@ Jv.call (Jv.of_string "data:") "concat" [| Jv.of_jstr mime_type; Jv.of_jstr (Jstr.v ";base64,"); base64data |] in send_raw ~filename data - (** Load the content at the given URL and return it The response body is only loaded if the result code is 200 *) let get_content_from_url : string -> (int * Jstr.t, Jv.Error.t) result Note.event = fun resource -> - Brr_io.Fetch.Request.v (Jstr.v resource) - |> Brr_io.Fetch.request - |> fun f -> + Brr_io.Fetch.Request.v (Jstr.v resource) |> Brr_io.Fetch.request |> fun f -> Fut.bind f (fun result -> match result with | Error e -> Fut.return (Error e) - | Ok response -> - (* Check the status before loading the response itself *) - ( match Brr_io.Fetch.Response.status response with - | 200 -> - Brr_io.Fetch.Response.as_body response - |> Brr_io.Fetch.Body.text - |> Fut.map - (Result.map (fun v -> - (Brr_io.Fetch.Response.status response, v) ) ) - | other -> Fut.return (Ok (other, Jstr.empty)) ) ) - |> Brr_note.Futr.to_event + | Ok response -> ( + (* Check the status before loading the response itself *) + match Brr_io.Fetch.Response.status response with + | 200 -> + Brr_io.Fetch.Response.as_body response + |> Brr_io.Fetch.Body.text + |> Fut.map + (Result.map (fun v -> + (Brr_io.Fetch.Response.status response, v))) + | other -> Fut.return (Ok (other, Jstr.empty)))) + |> Note_brr.Futr.to_event -- cgit v1.2.3