aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--bin/dune15
-rw-r--r--bin/login.eml13
-rw-r--r--bin/main.ml93
-rw-r--r--bin/template.eml43
4 files changed, 164 insertions, 0 deletions
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 =
+<body>
+ <h4>Login</h4>
+ <form class="input-validation-required">
+ <sl-input size="small" type="text" name="username" placeholder="username"></sl-input>
+ <br />
+ <sl-input size="small" type="password" name="password" placeholder="password">
+ <br />
+ </sl-input>
+ <br />
+ <sl-button size="small" type="Login" variant="primary">Submit</sl-button>
+ </form>
+</body>
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 _ -> "<p>You clicked</p>" |> 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) =
+<html>
+ <script src="https://unpkg.com/htmx.org@1.9.9"></script>
+ <link
+ rel="stylesheet"
+ href="https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.12.0/cdn/themes/light.css"
+ />
+ <script
+ type="module"
+ src="https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.12.0/cdn/shoelace-autoloader.js"
+ ></script>
+ <head>
+ <title>Sensemaking Links</title>
+ </head>
+ <body style="display:flex; flex-direction:column; align-items:center">
+ <h1>Sensemaking Links</h1>
+ <div>
+ <sl-button variant="text" size="medium" hx-post="/login" hx-swap="outerHTML">login</sl-button>
+ <sl-button variant="text" size="medium">rss</sl-button>
+ </div>
+% posts |> List.iter begin fun { author; link; summary; tags; _ } ->
+ <div>
+ <sl-card style="min-width: 400px; max-width: 600px; margin: 10px">
+ <div style="display:flex; flex-direction:column; gap: 10px">
+ <%s summary %>
+ <sl-button size="small" href=<%s link %>>Link (<%s Post.get_tld link %>)</sl-button>
+ </div>
+
+ <div slot="footer" style="display:flex; flex-direction:row; justify-content:space-between">
+ Submitted by: <%s author %>
+ <div style="display:flex; flex-direction:row; gap: 3px">
+% tags |> List.iter begin fun tag ->
+ <sl-tag size="small"><%s tag %></sl-tag>
+% end;
+ </div>
+ </div>
+ </div>
+% end;
+ </body>
+</html>