diff options
| author | eltrac <hi@eltr.ac> | 2026-04-13 17:13:12 +0800 |
|---|---|---|
| committer | eltrac <hi@eltr.ac> | 2026-04-13 17:13:12 +0800 |
| commit | cb1d3034b3ec04561f94497f31743371aab2d7be (patch) | |
| tree | 8f7d8bcbfd61dff71f6b2962d4cc9dcff6753480 /src | |
| parent | 734f7972f1a82d332f176ee308f7c3bef2af9353 (diff) | |
refactor: simplify webmention list query routes with macro
Diffstat (limited to 'src')
| -rw-r--r-- | src/weepinbell/handler.clj | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/src/weepinbell/handler.clj b/src/weepinbell/handler.clj index 7a2eec3..d7067f0 100644 --- a/src/weepinbell/handler.clj +++ b/src/weepinbell/handler.clj @@ -12,10 +12,18 @@ [weepinbell.feed :as feed] [clojure.core.async :refer [chan]])) -(def wmc (chan)) +;; Start webmention processor +(def wmc (chan)) (process-webmention wmc) +;; Define API routes + +(defmacro defmention-routes [base-path mention-type] + `(context ~base-path [] + (GET "/" [~'url] (retriever/by-url ~'url ~mention-type)) + (GET "/:domain" [~'domain] (retriever/by-domain ~'domain ~mention-type)))) + (defroutes api-routes (GET "/" [target] (ui/home (get-config :allowed-target-domains) (get-config :endpoint) @@ -26,19 +34,10 @@ ;; query API routes (context "/api" [] ;; query webmention list - (context "/mentions" [] - (GET "/" [url] (retriever/by-url url)) - (GET "/:domain" [domain] (retriever/by-domain domain))) - ;; query webmention list by microformats type - (context "/likes" [] - (GET "/" [url] (retriever/by-url url :like)) - (GET "/:domain" [domain] (retriever/by-domain domain :like))) - (context "/reposts" [] - (GET "/" [url] (retriever/by-url url :repost)) - (GET "/:domain" [domain] (retriever/by-domain domain :repost))) - (context "/replies" [] - (GET "/" [url] (retriever/by-url url :reply)) - (GET "/:domain" [domain] (retriever/by-domain domain :reply))) + (defmention-routes "/mentions" nil) + (defmention-routes "/likes" :like) + (defmention-routes "/reposts" :repost) + (defmention-routes "/replies" :reply) ;; query one specific webmention (context "/mention" [] (GET "/:id" [id] (retriever/by-id id)) |
