From 69d3f53365568524e18dfb1200a386309e174359 Mon Sep 17 00:00:00 2001 From: Marc Coquand Date: Sat, 2 Dec 2023 09:49:42 -0600 Subject: Initial commit --- bin/dune | 15 +++++++++ bin/login.eml | 13 ++++++++ bin/main.ml | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ bin/template.eml | 43 ++++++++++++++++++++++++++ 4 files changed, 164 insertions(+) create mode 100644 bin/dune create mode 100644 bin/login.eml create mode 100644 bin/main.ml create mode 100644 bin/template.eml (limited to 'bin') diff --git a/bin/dune b/bin/dune new file mode 100644 index 0000000..7126f64 --- /dev/null +++ b/bin/dune @@ -0,0 +1,15 @@ +(executable + (public_name wormhole) + (name main) + (libraries wormhole uri dream) + (preprocess (pps lwt_ppx ppx_yojson_conv))) + +(rule + (targets template.ml) + (deps template.eml) + (action (run dream_eml %{deps} --workspace %{workspace_root}))) + +(rule + (targets login.ml) + (deps login.eml) + (action (run dream_eml %{deps} --workspace %{workspace_root}))) diff --git a/bin/login.eml b/bin/login.eml new file mode 100644 index 0000000..44c1c47 --- /dev/null +++ b/bin/login.eml @@ -0,0 +1,13 @@ +let render = + +

Login

+
+ +
+ +
+
+
+ Submit +
+ diff --git a/bin/main.ml b/bin/main.ml new file mode 100644 index 0000000..dcd24aa --- /dev/null +++ b/bin/main.ml @@ -0,0 +1,93 @@ +open Wormhole + +let (fake_post : Post.t) = + { + link = "https://mccd.space"; + summary = "My personal blog"; + tags = [ "cool"; "article" ]; + published = "2020-01-01T00:00:00Z"; + author = "Marc"; + } + +let (fake_post_2 : Post.t) = + { + link = "https://google.com"; + summary = "Some other cool article that I just made"; + tags = [ "cool"; "something" ]; + published = "2020-01-02T00:00:00Z"; + author = "Bob"; + } + +let webfinger = + {| +{ + "subject": "acct:blackhole@galaxy.mccd.space", + + "links": [ + { + "rel": "self", + "type": "application/activity+json", + "href": "https://galaxy.mccd.space/actor" + } + ] +} +|} + +let actor = + {| +{ + "@context": [ + "https://www.w3.org/ns/activitystreams", + "https://w3id.org/security/v1" + ], + + "id": "https://galaxy.mccd.space/actor", + "type": "Person", + "preferredUsername": "blackhole", + "inbox": "https://galaxy.mccd.space/inbox", + + "publicKey": { + "id": "https://galaxy.mccd.space/actor#main-key", + "owner": "https://galaxy.mccd.space/actor", + "publicKeyPem": "-----BEGIN PUBLIC KEY-----MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvqa9W2PjNYB6FDuRewSR\nAUyH2TK5iprbfuKWvCGEYq2FRccjmoluMEb0a16AyqqMeZ8J+pI7cPvqpdXm/VVV\niZx3Q5W4H8kIC3I84qAAzVs3wOQWnudk+D+hEE1Il9+yFBFvF7IoyER9axqJEb88\nYQ5okLU/346SMpMrk4wsUFnwaxdVXQPBQ0tVxqVJiLGSMlGXX/1Vl0+lnhgg+5rH\n8rfIbFX4qQC/gYbEU+VS2nzhYjdqn0maL94OrFHYNdrMBgSBOtbBFSJ+kMgojqES\n7Xhf+G9JcuCIqm0T3dHqo50MUSx8lrS78S3uO7WgPAby8qXjcL8sQEfNvJT16sjk\ndwIDAQAB\n-----END PUBLIC KEY-----" + } +} + |} + +let () = + Post.add fake_post; + Post.add fake_post_2; + let port = + Sys.getenv_opt "PORT" |> Option.map int_of_string + |> Option.value ~default:8080 + in + let env = Sys.getenv_opt "ENV" |> Option.value ~default:"PROD" in + let interface = if env = "DEV" then "localhost" else "0.0.0.0" in + Dream.run ~port ~interface @@ Dream.logger + @@ Dream.router + [ + Dream.get "/actor" (fun _ -> + Dream.log "Sending actor"; + Dream.respond actor + ~headers:[ ("Content-Type", "application/json+ld") ]); + Dream.get "/.well-known/webfinger" (fun _ -> + Dream.log "Sending webfinger"; + Dream.respond webfinger + ~headers:[ ("Content-Type", "application/json+ld") ]); + Dream.get "/" (fun request -> + Dream.log "Sending greeting to %s!" (Dream.client request); + let posts = Post.get_all () in + Template.render posts |> Dream.html); + Dream.post "/clicked" (fun _ -> "

You clicked

" |> Dream.html); + Dream.post "/login" (fun _ -> Login.render |> Dream.html); + Dream.post "/inbox" (fun request -> + let%lwt body = Dream.body request in + Dream.log "Got body: %s" body; + 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 "{}"); + ] diff --git a/bin/template.eml b/bin/template.eml new file mode 100644 index 0000000..69d5dea --- /dev/null +++ b/bin/template.eml @@ -0,0 +1,43 @@ +open Wormhole +open Wormhole.Post + +let render (posts: Post.t list) = + + + + + + Sensemaking Links + + +

Sensemaking Links

+
+ login + rss +
+% posts |> List.iter begin fun { author; link; summary; tags; _ } -> +
+ +
+ <%s summary %> + >Link (<%s Post.get_tld link %>) +
+ +
+ Submitted by: <%s author %> +
+% tags |> List.iter begin fun tag -> + <%s tag %> +% end; +
+
+
+% end; + + -- cgit v1.2.3