diff options
author | Marc Coquand <marcc@fastmail.fr> | 2023-12-02 09:49:42 -0600 |
---|---|---|
committer | Marc Coquand <marcc@fastmail.fr> | 2023-12-02 09:49:42 -0600 |
commit | 69d3f53365568524e18dfb1200a386309e174359 (patch) | |
tree | 30e465d36ea03bceb1f4e9b54aadfdb6d7093162 /lib/post.ml | |
download | wormhole-69d3f53365568524e18dfb1200a386309e174359.tar.gz wormhole-69d3f53365568524e18dfb1200a386309e174359.tar.bz2 wormhole-69d3f53365568524e18dfb1200a386309e174359.zip |
Initial commit
Diffstat (limited to 'lib/post.ml')
-rw-r--r-- | lib/post.ml | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/post.ml b/lib/post.ml new file mode 100644 index 0000000..232d9a7 --- /dev/null +++ b/lib/post.ml @@ -0,0 +1,45 @@ +open Ppx_yojson_conv_lib.Yojson_conv.Primitives + +type t = { + link : string; + summary : string; + tags : string list; + published : string; + author : string; +} + +type mastodon_tag = { + kind : string; [@key "type"] + name : string; + href : string; +} +[@@deriving yojson] [@@yojson.allow_extra_fields] + +type mastodon_object = { tag : mastodon_tag list } +[@@deriving yojson] [@@yojson.allow_extra_fields] + +type mastodon_post = { + actor : string; + published : string; + obj : mastodon_object; [@key "object"] +} +[@@deriving yojson] [@@yojson.allow_extra_fields] + +let post_of_mastodon_post = function + | { actor; published; obj = { tag } } -> + let tags = List.map (fun { name; _ } -> name) tag in + { link = actor; summary = published; tags; published; author = actor } + +let get_tld (link : string) = + Uri.of_string link |> Uri.host_with_default ~default:"" + +let db = ref [] + +let add (entry : t) = + db := entry :: !db; + print_endline (entry.link ^ " added to db"); + print_endline ("New db size: " ^ string_of_int (List.length !db)) + +let get_all () = + print_endline ("db size: " ^ string_of_int (List.length !db)); + !db |