From bf25b247d989358af9a1a00f294d4de2a9c2d59c Mon Sep 17 00:00:00 2001 From: Arne Brasseur Date: Sun, 11 Dec 2022 15:06:47 +0100 Subject: [PATCH] start poking at webfinger --- deps.edn | 3 ++- repl_sessions/json_ld_stuff.clj | 4 ++-- repl_sessions/second_stream.clj | 6 +++--- repl_sessions/webfinger.clj | 37 +++++++++++++++++++++++++++++++++ src/lambdaisland/souk/db.clj | 4 ++-- 5 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 repl_sessions/webfinger.clj diff --git a/deps.edn b/deps.edn index 66c84ab..c368df1 100644 --- a/deps.edn +++ b/deps.edn @@ -31,7 +31,8 @@ org.slf4j/log4j-over-slf4j {:exclusions [org.slf4j/slf4j-nop], :mvn/version "2.0.3"} ch.qos.logback/logback-classic {:exclusions [org.slf4j/slf4j-api org.slf4j/slf4j-nop] :mvn/version "1.4.4"} - djblue/portal {:mvn/version "0.35.0"}} + djblue/portal {:mvn/version "0.35.0"} + lambdaisland/uri {:mvn/version "1.13.95"}} :aliases {:dev {:extra-paths ["dev"]} diff --git a/repl_sessions/json_ld_stuff.clj b/repl_sessions/json_ld_stuff.clj index 3c01780..fb9a687 100644 --- a/repl_sessions/json_ld_stuff.clj +++ b/repl_sessions/json_ld_stuff.clj @@ -1,8 +1,8 @@ (ns repl-sessions.json-ld-stuff (:require + [cheshire.core :as json] [clojure.string :as str] - [hato.client :as hato] - [cheshire.core :as json]) + [hato.client :as hato]) (:import (org.jsoup Jsoup))) (set! *print-namespace-maps* false) diff --git a/repl_sessions/second_stream.clj b/repl_sessions/second_stream.clj index 04a0b30..1b03370 100644 --- a/repl_sessions/second_stream.clj +++ b/repl_sessions/second_stream.clj @@ -7,13 +7,13 @@ (let [{:keys [schema ds]} (user/value :storage/db) table :activitystreams/Actor person (ap/GET "https://toot.cat/users/plexus/")] - #_ + (jdbc/execute! ds (db/insert-sql table (select-keys person (get schema table)) (apply dissoc person :rdf/type (get schema table)))) - [(select-keys person (get schema table)) - (apply dissoc person :rdf/type (get schema table))] + #_[(select-keys person (get schema table)) + (apply dissoc person :rdf/type (get schema table))] ) (count diff --git a/repl_sessions/webfinger.clj b/repl_sessions/webfinger.clj new file mode 100644 index 0000000..55134a8 --- /dev/null +++ b/repl_sessions/webfinger.clj @@ -0,0 +1,37 @@ +(ns repl-sessions.webfinger + (:require + [cheshire.core :as json] + [clojure.string :as str] + [hato.client :as hato] + [lambdaisland.uri :as uri])) + +;; all of these work +"acct:plexus@toot.cat" +"http://toot.cat/@plexus" +"https://toot.cat/@plexus" +"http://toot.cat/users/plexus" +"https://toot.cat/users/plexus" + +;; rel seems to be ignored + +(defn fetch-webfinger [domain resource] + (-> (uri/uri "https:///.well-known/webfinger") + (assoc :host domain) + (uri/assoc-query :resource resource) + str + (hato/get {:as :json}) + :body)) + +(fetch-webfinger "toot.cat" "acct:plexus@toot.cat") + +{:subject "acct:plexus@toot.cat", + :aliases ["https://toot.cat/@plexus" "https://toot.cat/users/plexus"], + :links + [{:rel "http://webfinger.net/rel/profile-page", + :type "text/html", + :href "https://toot.cat/@plexus"} + {:rel "self", + :type "application/activity+json", + :href "https://toot.cat/users/plexus"} + {:rel "http://ostatus.org/schema/1.0/subscribe", + :template "https://toot.cat/authorize_interaction?uri={uri}"}]} diff --git a/src/lambdaisland/souk/db.clj b/src/lambdaisland/souk/db.clj index 9093878..c817129 100644 --- a/src/lambdaisland/souk/db.clj +++ b/src/lambdaisland/souk/db.clj @@ -65,8 +65,8 @@ (cons (json/encode props) (concat - (map (comp pg-coerce val) props) - (map (comp pg-coerce val) props))))) + (map (comp pg-coerce val) entity) + (map (comp pg-coerce val) entity))))) (defn start! [{:keys [props]}] (let [ds (doto (ComboPooledDataSource.)