+2
-1
pegasus/lib/api/sync/getRepo.ml
+2
-1
pegasus/lib/api/sync/getRepo.ml
···
3
let handler =
4
Xrpc.handler (fun ctx ->
5
let {did; _} = Xrpc.parse_query ctx.req params_of_yojson in
6
+
let%lwt user_db = User_store.connect_readonly did in
7
+
let%lwt repo = Repository.load did ~ensure_active:true ~user_db in
8
let%lwt car_stream = Repository.export_car repo in
9
Dream.stream
10
~headers:[("Content-Type", "application/vnd.ipld.car")]
+9
pegasus/lib/data_store.ml
+9
pegasus/lib/data_store.ml
···
346
pool := Some db ;
347
Lwt.return db )
348
349
+
let connect_readonly ?create () =
350
+
if create = Some true then
351
+
Util.mkfile_p Util.Constants.pegasus_db_filepath ~perm:0o644 ;
352
+
let%lwt db =
353
+
Util.connect_sqlite ?create ~write:false Util.Constants.pegasus_db_location
354
+
in
355
+
let%lwt () = Migrations.run_migrations Data_store db in
356
+
Lwt.return db
357
+
358
let create_actor ~did ~handle ~email ~password ~signing_key conn =
359
let password_hash = Bcrypt.hash password |> Bcrypt.string_of_hash in
360
let now = Util.now_ms () in
+9
-5
pegasus/lib/repository.ml
+9
-5
pegasus/lib/repository.ml
···
413
in
414
Lwt.return {commit= new_commit; results}
415
416
-
let load ?create ?(ensure_active = false) did : t Lwt.t =
417
let%lwt ds_conn = Data_store.connect () in
418
let%lwt user_db =
419
-
try%lwt User_store.connect ?create did
420
-
with _ ->
421
-
Errors.invalid_request ~name:"RepoNotFound"
422
-
"your princess is in another castle"
423
in
424
let%lwt actor =
425
match%lwt Data_store.get_actor_by_identifier did ds_conn with
···
413
in
414
Lwt.return {commit= new_commit; results}
415
416
+
let load ?create ?(ensure_active = false) ?user_db did : t Lwt.t =
417
let%lwt ds_conn = Data_store.connect () in
418
let%lwt user_db =
419
+
match user_db with
420
+
| Some db ->
421
+
Lwt.return db
422
+
| None -> (
423
+
try%lwt User_store.connect ?create did
424
+
with _ ->
425
+
Errors.invalid_request ~name:"RepoNotFound"
426
+
"your princess is in another castle" )
427
in
428
let%lwt actor =
429
match%lwt Data_store.get_actor_by_identifier did ds_conn with
+13
-1
pegasus/lib/user_store.ml
+13
-1
pegasus/lib/user_store.ml
···
483
Hashtbl.replace pool_cache did t ;
484
Lwt.return t )
485
486
(* mst blocks; implements Writable_blockstore *)
487
488
let get_bytes t cid : Blob.t option Lwt.t =
···
528
if List.is_empty entries then Lwt.return_ok 0
529
else
530
Lwt_result.catch (fun () ->
531
-
let%lwt () = Util.use_pool t.db (fun conn -> Bulk.put_blocks entries conn) in
532
Lwt.return (List.length entries) )
533
534
let delete_block t cid : (bool, exn) Lwt_result.t =
···
483
Hashtbl.replace pool_cache did t ;
484
Lwt.return t )
485
486
+
let connect_readonly ?create did =
487
+
if create = Some true then
488
+
Util.mkfile_p (Util.Constants.user_db_filepath did) ~perm:0o644 ;
489
+
let%lwt db =
490
+
Util.connect_sqlite ?create ~write:false
491
+
(Util.Constants.user_db_location did)
492
+
in
493
+
let%lwt () = Migrations.run_migrations User_store db in
494
+
Lwt.return {did; db}
495
+
496
(* mst blocks; implements Writable_blockstore *)
497
498
let get_bytes t cid : Blob.t option Lwt.t =
···
538
if List.is_empty entries then Lwt.return_ok 0
539
else
540
Lwt_result.catch (fun () ->
541
+
let%lwt () =
542
+
Util.use_pool t.db (fun conn -> Bulk.put_blocks entries conn)
543
+
in
544
Lwt.return (List.length entries) )
545
546
let delete_block t cid : (bool, exn) Lwt_result.t =