objective categorical abstract machine language personal data server
65
fork

Configure Feed

Select the types of activity you want to include in your feed.

Return inclusion/exclusion proof from sync.getRecord

futurGH 3a9b578d 278cd091

+25 -8
+25 -8
pegasus/lib/api/sync/getRecord.ml
··· 1 - type query = {did: string; collection: string; rkey: string} [@@deriving yojson] 1 + module Mst = Mist.Mst.Make (User_store) 2 2 3 - type response = Mist.Lex.repo_record [@@deriving yojson] 3 + type query = {did: string; collection: string; rkey: string} [@@deriving yojson] 4 4 5 5 let handler = 6 6 Xrpc.handler (fun ctx -> ··· 8 8 Xrpc.parse_query ctx.req query_of_yojson 9 9 in 10 10 let path = collection ^ "/" ^ rkey in 11 - let%lwt {db; _} = Repository.load did ~write:false ~ds:ctx.db in 12 - match%lwt User_store.get_record_by_path db path with 13 - | Some {value; _} -> 14 - Dream.json @@ Yojson.Safe.to_string @@ response_to_yojson value 15 - | None -> 16 - Errors.invalid_request ~name:"RecordNotFound" "record not found" ) 11 + let%lwt {db; commit; _} = Repository.load did ~write:false ~ds:ctx.db in 12 + let commit_cid, commit_signed = Option.get commit in 13 + let commit_block = 14 + commit_signed |> User_store.Types.signed_commit_to_yojson 15 + |> Dag_cbor.encode_yojson 16 + in 17 + let mst_root = commit_signed.data in 18 + let%lwt blocks = 19 + Mst.proof_for_key {blockstore= db; root= mst_root} mst_root path 20 + in 21 + let blocks_stream = 22 + Repository.BlockMap.entries blocks |> Lwt_seq.of_list 23 + in 24 + let car_stream = 25 + Lwt_seq.cons (commit_cid, commit_block) blocks_stream 26 + |> Car.blocks_to_stream commit_cid 27 + in 28 + Dream.stream 29 + ~headers:[("Content-Type", "application/vnd.ipld.car")] 30 + (fun res_stream -> 31 + Lwt_seq.iter_s 32 + (fun chunk -> Dream.write res_stream (Bytes.to_string chunk)) 33 + car_stream ) )