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 empty stream instead of 404 for missing record on sync.getRecord

futurGH 56ef5dd2 abc7f7a9

+35 -33
+35 -33
pegasus/lib/api/sync/getRecord.ml
··· 6 6 let {did; collection; rkey} = Xrpc.parse_query ctx.req params_of_yojson in 7 7 let path = collection ^ "/" ^ rkey in 8 8 let%lwt repo = Repository.load did ~ensure_active:true in 9 - match%lwt Repository.get_record repo path with 10 - | None -> 11 - Printf.ksprintf 12 - (Errors.not_found ?name:None) 13 - "record %s not found" 14 - ("at://" ^ did ^ "/" ^ path) 15 - | Some record -> 16 - let record_block = Mist.Lex.repo_record_to_cbor_block record.value in 17 - let commit_cid, commit_signed = Option.get repo.commit in 18 - let commit_block = 19 - commit_signed |> User_store.Types.signed_commit_to_yojson 20 - |> Dag_cbor.encode_yojson 21 - in 22 - let mst_root = commit_signed.data in 23 - let%lwt blocks = 24 - Mst.proof_for_key 25 - {blockstore= repo.db; root= mst_root} 26 - mst_root path 27 - in 28 - let blocks_stream = 29 - Repository.Block_map.entries blocks |> Lwt_seq.of_list 30 - in 31 - let car_stream = 32 - Lwt_seq.cons (commit_cid, commit_block) 33 - @@ Lwt_seq.cons record_block blocks_stream 34 - |> Car.blocks_to_stream commit_cid 35 - in 36 - Dream.stream 37 - ~headers:[("Content-Type", "application/vnd.ipld.car")] 38 - (fun res_stream -> 39 - Lwt_seq.iter_s 40 - (fun chunk -> Dream.write res_stream (Bytes.to_string chunk)) 41 - car_stream ) ) 9 + let commit_cid, commit_signed = Option.get repo.commit in 10 + let commit_block = 11 + commit_signed |> User_store.Types.signed_commit_to_yojson 12 + |> Dag_cbor.encode_yojson 13 + in 14 + let mst_root = commit_signed.data in 15 + let%lwt record = Repository.get_record repo path in 16 + let%lwt record_blocks = 17 + match record with 18 + | Some record -> 19 + let record_block = 20 + Mist.Lex.repo_record_to_cbor_block record.value 21 + in 22 + let%lwt blocks = 23 + Mst.proof_for_key 24 + {blockstore= repo.db; root= mst_root} 25 + mst_root path 26 + in 27 + let blocks_stream = 28 + Repository.Block_map.entries blocks |> Lwt_seq.of_list 29 + in 30 + Lwt.return @@ Lwt_seq.cons record_block blocks_stream 31 + | None -> 32 + Lwt.return Lwt_seq.empty 33 + in 34 + let car_stream = 35 + Lwt_seq.cons (commit_cid, commit_block) record_blocks 36 + |> Car.blocks_to_stream commit_cid 37 + in 38 + Dream.stream 39 + ~headers:[("Content-Type", "application/vnd.ipld.car")] 40 + (fun res_stream -> 41 + Lwt_seq.iter_s 42 + (fun chunk -> Dream.write res_stream (Bytes.to_string chunk)) 43 + car_stream ) )