summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoreltrac <hi@eltr.ac>2026-10-04 17:06:03 +0800
committereltrac <hi@eltr.ac>2026-10-04 17:07:10 +0800
commit61afc1a7cc45a1ab3a5d141c1a490badf3ea03ef (patch)
tree7158a08f04af53b6437f54486850f611559a8160 /src
parentb13b6ad1c2e9127412583760ff3d75e0e958e207 (diff)
API: remove typed API
- /api/likes removed - /api/replies removed - /api/reposts removed
Diffstat (limited to 'src')
-rw-r--r--src/weepinbell/handler.clj24
-rw-r--r--src/weepinbell/retriever.clj19
2 files changed, 15 insertions, 28 deletions
diff --git a/src/weepinbell/handler.clj b/src/weepinbell/handler.clj
index 0c45960..079c1e1 100644
--- a/src/weepinbell/handler.clj
+++ b/src/weepinbell/handler.clj
@@ -12,26 +12,22 @@
;; Define API routes
-(defmacro defmention-routes [base-path mention-type storage]
- `(context ~base-path []
- (GET "/" [~'url ~'page ~'microformats]
- (retriever/by-url ~'url ~mention-type ~'page ~storage
- {:microformats ~'microformats}))
- (GET "/:domain" [~'domain ~'page ~'microformats]
- (retriever/by-domain ~'domain ~mention-type ~'page ~storage
- {:microformats ~'microformats}))))
-
(defn make-api [wmc storage config]
[;; receiver endpoint
(POST (:endpoint config) [source target]
(receive {:s source :t target} wmc config))
;; query API routes
(context "/api" []
- ;; query webmention list
- (defmention-routes "/mentions" nil storage)
- (defmention-routes "/likes" :like storage)
- (defmention-routes "/reposts" :repost storage)
- (defmention-routes "/replies" :reply storage)
+ ;; query webmention list
+ (context "/mentions" [page microformats mftype]
+ (GET "/" [url]
+ (retriever/by-url url page storage
+ {:microformats microformats
+ :type mftype}))
+ (GET "/:domain" [domain]
+ (retriever/by-domain domain page storage
+ {:microformats microformats
+ :type mftype})))
;; query one specific webmention
(context "/mention" [microformats]
(GET "/:id" [id] (retriever/by-id id storage
diff --git a/src/weepinbell/retriever.clj b/src/weepinbell/retriever.clj
index e3b288d..864f839 100644
--- a/src/weepinbell/retriever.clj
+++ b/src/weepinbell/retriever.clj
@@ -54,37 +54,28 @@
(defn- wrap-response-list [opts data]
(map #(wrap-response-object % opts) data))
-(defn- get-mftype-key [typ]
- (get {:like :like-of
- :repost :repost-of
- :reply :in-reply-to
- :rsvp :rsvp} typ))
-
(defn- filter-response-by-mftype [typ data]
- (when typ
- (filter #(= (-> % :microformats :type)
- (get-mftype-key typ))
- data)))
+ (filter #(= typ (get-in % [:microformats :type])) data))
;; end utilities
(defn by-domain
"Get webmentions sent to a particular domain."
- [domain typ page storage opts]
+ [domain page storage opts]
(cond->> ((:get-by-domain storage) domain)
true (wrap-response-list opts)
- typ (filter-response-by-mftype typ)
+ (:type opts) (filter-response-by-mftype (:type opts))
page (partition-pages page default-page-size)
true respond-webmention-list-json))
(defn by-url
"Get webmention sent to a particular URL."
- [url typ page storage opts]
+ [url page storage opts]
(if url
(cond->> (get-domain url)
true ((:get-by-domain storage))
true (filter #(= url (get-in % [:webmention :target])))
true (wrap-response-list opts)
- typ (filter-response-by-mftype typ)
+ (:type opts) (filter-response-by-mftype (:type opts))
page (partition-pages page default-page-size)
true respond-webmention-list-json)
;; if no url query is passed