objective categorical abstract machine language personal data server
65
fork

Configure Feed

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

xrpc getRepoStatus, listRepos

futurGH 367e247f b96419d1

+98 -5
+3 -1
bin/main.ml
··· 40 40 ; (post, "/xrpc/com.atproto.repo.deleteRecord", Api.Repo.DeleteRecord.handler) 41 41 ; (post, "/xrpc/com.atproto.repo.uploadBlob", Api.Repo.UploadBlob.handler) 42 42 ; (* sync *) 43 - (get, "/xrpc/com.atproto.sync.getBlob", Api.Sync.GetBlob.handler) 43 + (get, "/xrpc/com.atproto.sync.getRepoStatus", Api.Sync.GetRepoStatus.handler) 44 + ; (get, "/xrpc/com.atproto.sync.listRepos", Api.Sync.ListRepos.handler) 45 + ; (get, "/xrpc/com.atproto.sync.getBlob", Api.Sync.GetBlob.handler) 44 46 ; (get, "/xrpc/com.atproto.sync.listBlobs", Api.Sync.ListBlobs.handler) 45 47 ; (* preferences *) 46 48 ( get
+34
pegasus/lib/api/sync/getRepoStatus.ml
··· 1 + type query = {did: string} [@@deriving yojson] 2 + 3 + type response = 4 + {did: string; active: bool; status: string option; rev: string option} 5 + [@@deriving yojson] 6 + 7 + let handler = 8 + Xrpc.handler (fun ctx -> 9 + let {did} : query = Xrpc.parse_query ctx.req query_of_yojson in 10 + let%lwt actor = 11 + match%lwt Data_store.get_actor_by_identifier did ctx.db with 12 + | Some actor -> 13 + Lwt.return actor 14 + | None -> 15 + Errors.invalid_request ~name:"RepoNotFound" 16 + "couldn't find a repo with that did" 17 + in 18 + let%lwt user_db = User_store.connect actor.did in 19 + let%lwt _, commit = 20 + match%lwt User_store.get_commit user_db with 21 + | Some c -> 22 + Lwt.return c 23 + | None -> 24 + failwith ("failed to retrieve commit for " ^ actor.did) 25 + in 26 + let active, status, rev = 27 + match actor.deactivated_at with 28 + | Some _ -> 29 + (false, Some "deactivated", None) 30 + | None -> 31 + (true, None, Some commit.rev) 32 + in 33 + Dream.json @@ Yojson.Safe.to_string 34 + @@ response_to_yojson {did; active; status; rev} )
+3 -1
pegasus/lib/api/sync/listBlobs.ml
··· 20 20 let%lwt db = User_store.connect did in 21 21 let%lwt cids = User_store.list_blobs db ~limit ~cursor ?since in 22 22 let cids = List.map Cid.to_string cids in 23 - let cursor = if List.length cids = limit then Some cursor else None in 23 + let cursor = 24 + if List.length cids = limit then Mist.Util.last cids else None 25 + in 24 26 Dream.json @@ Yojson.Safe.to_string @@ response_to_yojson {cursor; cids} )
+53
pegasus/lib/api/sync/listRepos.ml
··· 1 + type query = {cursor: string option; limit: int option} [@@deriving yojson] 2 + 3 + type response = {cursor: string option; repos: res_repo list} 4 + [@@deriving yojson] 5 + 6 + and res_repo = 7 + { did: string 8 + ; head: string 9 + ; rev: string 10 + ; active: bool option 11 + ; status: string option } 12 + [@@deriving yojson] 13 + 14 + let handler = 15 + Xrpc.handler (fun ctx -> 16 + let {cursor; limit} = Xrpc.parse_query ctx.req query_of_yojson in 17 + let limit = 18 + match limit with 19 + | Some limit when limit > 0 && limit <= 1000 -> 20 + limit 21 + | _ -> 22 + 1000 23 + in 24 + let%lwt actors = Data_store.list_actors ?cursor ~limit ctx.db in 25 + let%lwt repos = 26 + List.map 27 + (fun (a : Data_store.Types.actor) -> 28 + let%lwt user_db = User_store.connect a.did in 29 + let%lwt head, {rev; _} = 30 + match%lwt User_store.get_commit user_db with 31 + | Some c -> 32 + Lwt.return c 33 + | None -> 34 + failwith ("failed to retrieve commit for " ^ a.did) 35 + in 36 + let active, status = 37 + match a.deactivated_at with 38 + | Some _ -> 39 + (Some false, Some "deactivated") 40 + | None -> 41 + (Some true, None) 42 + in 43 + Lwt.return 44 + {did= a.did; head= Cid.to_string head; rev; active; status} ) 45 + actors 46 + |> Lwt.all 47 + in 48 + let cursor = 49 + if List.length repos = limit then 50 + Option.map (fun r -> r.did) @@ Mist.Util.last repos 51 + else None 52 + in 53 + Dream.json @@ Yojson.Safe.to_string @@ response_to_yojson {cursor; repos} )
+5 -3
pegasus/lib/data_store.ml
··· 119 119 get_many 120 120 {sql| SELECT @int{id}, @string{did}, @string{handle}, @string{email}, @string{password_hash}, @string{signing_key}, @Json{preferences}, @int{created_at}, @int?{deactivated_at} 121 121 FROM actors 122 - ORDER BY created_at DESC LIMIT %int{limit} OFFSET %int{offset} 122 + WHERE did > %string{cursor} 123 + AND deactivated_at IS NULL 124 + ORDER BY created_at DESC LIMIT %int{limit} 123 125 |sql} 124 126 record_out] 125 127 ··· 221 223 | _ -> 222 224 Lwt.return_none ) 223 225 224 - let list_actors ?(limit = 100) ?(offset = 0) conn = 225 - unwrap @@ Queries.list_actors ~limit ~offset conn 226 + let list_actors ?(cursor = "") ?(limit = 100) conn = 227 + unwrap @@ Queries.list_actors ~cursor ~limit conn 226 228 227 229 let put_preferences ~did ~prefs conn = 228 230 unwrap @@ Queries.put_preferences ~did ~preferences:prefs conn