summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoreltrac <hi@eltr.ac>2026-03-17 15:11:05 +0800
committereltrac <hi@eltr.ac>2026-03-17 15:11:05 +0800
commit738e28fbf6c49d69f9a1db9f28b701abd0407bec (patch)
treefb069ab52345b2da4e6f4d97bad55653802109b6 /src
parent260e604fe905b4c2e14a78843ef627639ea633e0 (diff)
feat(handler): new API route for getting webmention list
Diffstat (limited to 'src')
-rw-r--r--src/weepinbell/handler.clj3
-rw-r--r--src/weepinbell/retriever.clj27
2 files changed, 28 insertions, 2 deletions
diff --git a/src/weepinbell/handler.clj b/src/weepinbell/handler.clj
index fa1b509..a52206b 100644
--- a/src/weepinbell/handler.clj
+++ b/src/weepinbell/handler.clj
@@ -17,6 +17,9 @@
(POST (get-config :endpoint) [source target]
(receive {:s source :t target} wmc))
;; query webmentions
+ (GET "/api/mentions/" [url] (retriever/by-url url))
+ (GET "/api/mentions/:domain" [domain] (retriever/by-domain domain))
+ (GET "/api/mentions/:domain/:path" [domain path] (retriever/by-domain-path domain path))
(GET "/api/mentions/all" [filter] (retriever/all filter))
;; query one specific webmention
(GET "/api/mention/:id" [id] (retriever/by-id id))
diff --git a/src/weepinbell/retriever.clj b/src/weepinbell/retriever.clj
index 7240e2d..1dd75a5 100644
--- a/src/weepinbell/retriever.clj
+++ b/src/weepinbell/retriever.clj
@@ -1,7 +1,12 @@
(ns weepinbell.retriever
(:require [weepinbell.storage :as storage]
- [weepinbell.utils :refer [valid-http-url? get-domain get-target respond-json]]
- [clojure.string :refer [includes?]]))
+ [weepinbell.utils :refer [valid-http-url?
+ get-domain
+ get-path
+ get-target
+ respond-json]]
+ [clojure.string :refer [includes?]]
+ [cheshire.core :as json]))
;; utilities
(defn- respond-webmention-json [data]
@@ -26,6 +31,24 @@
:else identity)] ;; Use identity instead of not-empty for "no filter"
(respond-json (filter pred data))))
+(defn by-domain
+ "Get webmentions sent to a particular domain."
+ [domain]
+ (let [data (storage/get-wms-by-domain domain)]
+ (respond-json data)))
+
+(defn by-domain-path
+ "Get webmention sent to a particular path on a particular domain. More flexible than bare URL."
+ [domain path]
+ (let [data (storage/get-wms-by-domain domain path)]
+ (respond-json data)))
+
+(defn by-url
+ "Get webmention sent to a particular URL."
+ [url]
+ (let [domain (get-domain url)
+ path (get-path url)]
+ (by-domain-path domain path)))
(defn by-id
"Get one specific webmention by ID."