From 189179574d847e8e9662cf78804ce9371fac988d Mon Sep 17 00:00:00 2001 From: Marc Coquand Date: Sat, 2 Dec 2023 11:25:36 -0600 Subject: Add user --- bin/main.ml | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'bin') diff --git a/bin/main.ml b/bin/main.ml index dcd24aa..67c9786 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -21,7 +21,7 @@ let (fake_post_2 : Post.t) = let webfinger = {| { - "subject": "acct:blackhole@galaxy.mccd.space", + "subject": "acct:wormhole@galaxy.mccd.space", "links": [ { @@ -43,7 +43,7 @@ let actor = "id": "https://galaxy.mccd.space/actor", "type": "Person", - "preferredUsername": "blackhole", + "preferredUsername": "wormhole", "inbox": "https://galaxy.mccd.space/inbox", "publicKey": { @@ -86,8 +86,20 @@ let () = let message_object = Yojson.Safe.from_string body |> Post.mastodon_post_of_yojson in - message_object |> Post.yojson_of_mastodon_post - |> Yojson.Safe.to_string |> Dream.log "Added post %s"; - message_object |> Post.post_of_mastodon_post |> Post.add; - Dream.json "{}"); + let%lwt actor = + User.get_user (Post.mastodon_actor message_object) + in + match actor with + | Error e -> + Dream.log "User not found %s" (Printexc.to_string e); + let code = Some 400 in + Dream.json ?code "User not found" + | Ok actor -> + Dream.log "User found"; + message_object + |> Post.post_of_mastodon_post (User.name actor) + |> Post.add; + message_object |> Post.yojson_of_mastodon_post + |> Yojson.Safe.to_string |> Dream.log "Added post %s"; + Dream.json "{}"); ] -- cgit v1.2.3