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 getPreferences, putPreferences

futurGH b478d66c 71d02032

+42 -3
+11
pegasus/lib/api/actor/getPreferences.ml
··· 1 + let handler = 2 + Xrpc.handler ~auth:Auth.Verifiers.access (fun {db; auth; _} -> 3 + let did = Auth.get_authed_did_exn auth in 4 + let%lwt prefs = 5 + match%lwt Data_store.get_actor_by_identifier did db with 6 + | Some actor -> 7 + Lwt.return actor.preferences 8 + | None -> 9 + Util.Exceptions.Errors.internal_error () 10 + in 11 + Dream.json @@ Yojson.Safe.to_string prefs )
+13
pegasus/lib/api/actor/putPreferences.ml
··· 1 + let handler = 2 + Xrpc.handler ~auth:Auth.Verifiers.access (fun {req; db; auth} -> 3 + let did = Auth.get_authed_did_exn auth in 4 + let%lwt body = Dream.body req in 5 + let prefs = 6 + match Yojson.Safe.from_string body with 7 + | `Assoc [("preferences", prefs)] -> 8 + prefs 9 + | _ -> 10 + Util.Exceptions.Errors.invalid_request "Invalid request body" 11 + in 12 + let%lwt () = Data_store.put_preferences ~did ~prefs db in 13 + Dream.empty `OK )
+1 -3
pegasus/lib/api/server/getSession.ml
··· 2 2 3 3 let handler = 4 4 Xrpc.handler ~auth:Auth.Verifiers.access (fun {db; auth; _} -> 5 - let did = 6 - match auth with Access {did} -> did | _ -> failwith "non-access auth" 7 - in 5 + let did = Auth.get_authed_did_exn auth in 8 6 let%lwt session = Auth.get_session_info did db in 9 7 Dream.json @@ Yojson.Safe.to_string @@ Auth.session_info_to_yojson session )
+8
pegasus/lib/auth.ml
··· 98 98 | _ -> 99 99 false 100 100 101 + let get_authed_did_exn = function 102 + | Access {did} -> 103 + did 104 + | Refresh {did; _} -> 105 + did 106 + | _ -> 107 + Util.Exceptions.Errors.auth_required "Invalid authorization header" 108 + 101 109 let get_session_info identifier db = 102 110 let%lwt actor = 103 111 match%lwt Data_store.get_actor_by_identifier identifier db with
+9
pegasus/lib/data_store.ml
··· 117 117 |sql} 118 118 record_out] 119 119 120 + let put_preferences = 121 + [%rapper 122 + execute 123 + {sql| UPDATE actors SET preferences = %Json{preferences} WHERE did = %string{did} 124 + |sql}] 125 + 120 126 (* firehose *) 121 127 let firehose_insert = 122 128 [%rapper ··· 205 211 206 212 let list_actors ?(limit = 100) ?(offset = 0) conn = 207 213 unwrap @@ Queries.list_actors ~limit ~offset conn 214 + 215 + let put_preferences ~did ~prefs conn = 216 + unwrap @@ Queries.put_preferences ~did ~preferences:prefs conn 208 217 209 218 (* firehose helpers *) 210 219 let append_firehose_event conn ~time ~t ~data : int Lwt.t =