From 10a4e0f8bb567ee7e0c88d9666c7ac38ba4dbb0d Mon Sep 17 00:00:00 2001 From: Aleteoryx Date: Fri, 22 Nov 2024 19:36:34 -0500 Subject: [PATCH] did.json --- main.tcl | 24 +++++++++++++++++++----- src/feed.tcl | 22 +++++++++++++--------- src/httpd.tcl | 10 ++++++++++ 3 files changed, 42 insertions(+), 14 deletions(-) diff --git a/main.tcl b/main.tcl index 8e467a0..5c45c12 100755 --- a/main.tcl +++ b/main.tcl @@ -62,15 +62,29 @@ db_cleanup [::ini::value $config database cleanup_interval] [::ini::value $confi jetstream::listen [::ini::value $config atproto jetstream_host] $::algos::list ### HTTPD ### -httpd::router main [list \ - /xrpc/app.bsky.feed.getFeedSkeleton [list ::feed::serve_skeleton \ + +set routes {} + +set well_known [ + ::feed::well_known \ $::algos::list \ - [::ini::value $config atproto publisher_did]] \ - /xrpc/app.bsky.feed.describeFeedGenerator [list ::feed::serve_generator_description \ + [::ini::value $config atproto self_host]] +lappend routes /.well-known/did.json \ + [list ::httpd::serve application/json $well_known] + +lappend routes /xrpc/app.bsky.feed.getFeedSkeleton \ + [list ::feed::serve_skeleton $::algos::list [::ini::value $config atproto publisher_did]] + +set generator_description [ + ::feed::generator_description \ $::algos::list \ [::ini::value $config atproto publisher_did] \ [::ini::value $config atproto self_host]] -] +lappend /xrpc/app.bsky.feed.describeFeedGenerator \ + [list ::httpd::serve application/json $generator_description]] + +httpd::router main $routes + httpd::listen main [::ini::value $config httpd port] vwait nil diff --git a/src/feed.tcl b/src/feed.tcl index cdb7db3..7b4cc1c 100644 --- a/src/feed.tcl +++ b/src/feed.tcl @@ -76,7 +76,7 @@ namespace eval feed { return } - proc ::feed::serve_generator_description {feeds publisher self_host _ sock path query headers} { + proc ::feed::generator_description {feeds publisher self_host} { set feed_uris {} foreach feed $feeds { lappend feed_uris [::json::write object \ @@ -87,13 +87,17 @@ namespace eval feed { did [::json::write string "did:web:$self_host"] \ feeds $feed_uris] - puts $sock "HTTP/1.0 200 OK" - puts $sock "Content-Type: application/json" - puts $sock "Content-Length: [string length $description]" - puts $sock "" - fconfigure $sock -translation binary - puts -nonewline $sock $description - close $sock - return + return $description + } + + proc ::feed::well_known {feeds self_host} { + ::json::write object \ + @context {["https://www.w3.org/ns/did/v1"]} \ + id [::json::write string did:web:$self_host] \ + service [::json::write array \ + [::json::write object \ + id {"#bsky_fg"} \ + serviceEndpoint [::json::write string https://$self_host] \ + type {"BskyFeedGenerator"}]] } } diff --git a/src/httpd.tcl b/src/httpd.tcl index a16409a..52cf96a 100644 --- a/src/httpd.tcl +++ b/src/httpd.tcl @@ -79,4 +79,14 @@ namespace eval ::httpd { flush $sock close $sock } + + proc ::httpd::serve {mime payload _ sock _ _ _} { + puts $sock "HTTP/1.0 200 OK" + puts $sock "Content-Type: $mime" + puts $sock "Content-Length: [string length $payload]" + puts $sock "" + fconfigure $sock -translation binary + puts -nonewline $sock $payload + close $sock + } } -- 2.45.2