aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorMarc Coquand <marcc@fastmail.fr>2023-12-02 11:25:36 -0600
committerMarc Coquand <marcc@fastmail.fr>2023-12-02 11:25:36 -0600
commit189179574d847e8e9662cf78804ce9371fac988d (patch)
tree0cc2b8c27fe8cf59d4724100d8b95085fab6432d /bin
parent4fe8c79ce03e12be04b0d928b65b1a7d475f4458 (diff)
downloadwormhole-189179574d847e8e9662cf78804ce9371fac988d.tar.gz
wormhole-189179574d847e8e9662cf78804ce9371fac988d.tar.bz2
wormhole-189179574d847e8e9662cf78804ce9371fac988d.zip
Add user
Diffstat (limited to 'bin')
-rw-r--r--bin/main.ml24
1 files changed, 18 insertions, 6 deletions
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 "{}");
]