From 59f3b1b7899e11a7b6c117e25041245c8acf65d6 Mon Sep 17 00:00:00 2001 From: "Jakob L. Kreuze" Date: Sat, 3 Dec 2022 12:57:43 -0500 Subject: [dynamic] Reach out to API instead of PostgreSQL --- haunt/jakob/dynamic/capabilities/comments.scm | 1 + haunt/jakob/dynamic/rate-limiter.scm | 5 ++++- haunt/jakob/utils/comments.scm | 10 +++++++++- 3 files changed, 14 insertions(+), 2 deletions(-) (limited to 'haunt') diff --git a/haunt/jakob/dynamic/capabilities/comments.scm b/haunt/jakob/dynamic/capabilities/comments.scm index ee4172c..1346ee4 100644 --- a/haunt/jakob/dynamic/capabilities/comments.scm +++ b/haunt/jakob/dynamic/capabilities/comments.scm @@ -33,6 +33,7 @@ put-comment put-reaction + json->internal-comment internal-comment? internal-comment-id internal-comment-name diff --git a/haunt/jakob/dynamic/rate-limiter.scm b/haunt/jakob/dynamic/rate-limiter.scm index d6ef28c..fb251a1 100644 --- a/haunt/jakob/dynamic/rate-limiter.scm +++ b/haunt/jakob/dynamic/rate-limiter.scm @@ -35,7 +35,10 @@ (define active-rate-limits (make-hash-table)) -(define (rate-limit-for-endpoint name) 32) +(define (rate-limit-for-endpoint name) + (case name + ((get-comments) 1024) + (else 32))) (define (increment-key! hash-table key) (let ((new-value (if (hash-ref hash-table key) diff --git a/haunt/jakob/utils/comments.scm b/haunt/jakob/utils/comments.scm index e228a6d..8678a3a 100644 --- a/haunt/jakob/utils/comments.scm +++ b/haunt/jakob/utils/comments.scm @@ -213,7 +213,15 @@ (define (fetch-comments slug) "Blocking call to webmention.io to retrieve a vector of all Webmentions for `slug'" - (get-comments-by-slug slug)) + (let ((url (format #f "https://jakob.space/api/comments?p=~a" slug))) + (receive (response-status response-body) + (http-request url) + (chain response-body + (bytevector->string _ "UTF-8") + (json-string->scm _) + (vector->list _) + (map scm->json-string _) + (map (lambda (x) (call-with-input-string x json->internal-comment)) _))))) (define (fetch-webmentions slug) "Blocking call to webmention.io to retrieve a vector of all Webmentions for `slug'" -- cgit v1.3