From 6a226e9eefe2037e397786ace27aa99e1a02a9e9 Mon Sep 17 00:00:00 2001 From: Aleteoryx Date: Fri, 22 Nov 2024 14:08:13 -0500 Subject: [PATCH] describeFeedGenerator endpoint --- config.example.ini | 1 + main.tcl | 8 +++++++- src/config.tcl | 1 + src/feed.tcl | 28 ++++++++++++++++++++++++---- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/config.example.ini b/config.example.ini index 8c9400c..e22711d 100644 --- a/config.example.ini +++ b/config.example.ini @@ -4,3 +4,4 @@ path = posts.db [atproto] jetstream_host = jetstream2.us-east.bsky.network ; publisher_did = +; self_host = diff --git a/main.tcl b/main.tcl index c633ef0..8e467a0 100755 --- a/main.tcl +++ b/main.tcl @@ -63,7 +63,13 @@ jetstream::listen [::ini::value $config atproto jetstream_host] $::algos::list ### HTTPD ### httpd::router main [list \ - /xrpc/app.bsky.feed.getFeedSkeleton [list ::feed::serve_skeleton $::algos::list [::ini::value $config atproto publisher_did]] \ + /xrpc/app.bsky.feed.getFeedSkeleton [list ::feed::serve_skeleton \ + $::algos::list \ + [::ini::value $config atproto publisher_did]] \ + /xrpc/app.bsky.feed.describeFeedGenerator [list ::feed::serve_generator_description \ + $::algos::list \ + [::ini::value $config atproto publisher_did] \ + [::ini::value $config atproto self_host]] ] httpd::listen main [::ini::value $config httpd port] diff --git a/src/config.tcl b/src/config.tcl index 71f5d99..8f3387b 100644 --- a/src/config.tcl +++ b/src/config.tcl @@ -35,6 +35,7 @@ namespace eval ::config { require $config atproto jetstream_host require $config atproto publisher_did + require $config atproto self_host optional $config httpd port 3000 ${log}::info "Config loaded!..." diff --git a/src/feed.tcl b/src/feed.tcl index 1a00a09..cdb7db3 100644 --- a/src/feed.tcl +++ b/src/feed.tcl @@ -58,10 +58,13 @@ namespace eval feed { set feed_data {} foreach uri [db eval "SELECT uri FROM $feed ORDER BY ord DESC LIMIT $limit OFFSET $cursor;"] { - lappend feed_data [::json::write object post [::json::write string $uri]] + lappend feed_data [::json::write object \ + post [::json::write string $uri]] } set feed_data_arr [::json::write array {*}$feed_data] - set feed_contents [::json::write object cursor [expr {$cursor + min([llength $feed_data], $limit)}] feed $feed_data_arr] + set feed_contents [::json::write object \ + cursor [expr {$cursor + min([llength $feed_data], $limit)}] \ + feed $feed_data_arr] puts $sock "HTTP/1.0 200 OK" puts $sock "Content-Type: application/json" @@ -73,7 +76,24 @@ namespace eval feed { return } - proc ::feed::serve_generator_description {feeds publisher _ sock path query headers} { - + proc ::feed::serve_generator_description {feeds publisher self_host _ sock path query headers} { + set feed_uris {} + foreach feed $feeds { + lappend feed_uris [::json::write object \ + uri [::json::write string "at://$publisher/app.bsky.feed.generator/$feed"]] + } + set feed_uris [::json::write array {*}$feed_uris] + set description [::json::write object \ + 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 } } -- 2.45.2