summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoreltrac <hi@eltr.ac>2026-05-12 10:38:14 +0800
committereltrac <hi@eltr.ac>2026-05-12 10:38:36 +0800
commit26b8fd9765f3a50094f7ab1f0207eedf55c613e9 (patch)
treebd024c530ebd32c1f6c1cf708d7148c23f997fc8 /src
parent0084a313e424a6a21a9b13ad59b8666d668066c2 (diff)
refactor(receiver): do not depend on config directly
Diffstat (limited to 'src')
-rw-r--r--src/weepinbell/receiver.clj20
1 files changed, 8 insertions, 12 deletions
diff --git a/src/weepinbell/receiver.clj b/src/weepinbell/receiver.clj
index 34dfdc1..772916f 100644
--- a/src/weepinbell/receiver.clj
+++ b/src/weepinbell/receiver.clj
@@ -3,7 +3,6 @@
(:require [clojure.string :as string]
[clojure.core.async :refer [put!]]
[weepinbell.utils :refer [valid-http-url? get-domain]]
- [weepinbell.config :refer [get-config]]
[md5.core :refer [string->md5-hex]]))
;; validation and verification
@@ -11,10 +10,8 @@
(defn- validate-urls [s t]
(and (valid-http-url? s) (valid-http-url? t)))
-(defn- validate-target [t opts]
- (let [target-domain (get-domain t)
- allow-list (or (:domains opts)
- (get-config :allowed-target-domains))]
+(defn- validate-target [t allow-list]
+ (let [target-domain (get-domain t)]
(some #{target-domain} allow-list)))
(defn- verify-request
@@ -37,15 +34,14 @@
(defn receive
"Receive webmention; call verify-request; if verification passed, push webmention into queue."
- ([wm wmc]
- (receive wm wmc {}))
- ([wm wmc opts]
- (let [{:keys [s t]} wm
+ [wm wmc config]
+ (let [{:keys [s t]} wm
;; remove anchor, #...
source (some-> s (string/replace #"#.*$" ""))
target (some-> t (string/replace #"#.*$" ""))]
;; Request verification
- (if-let [error-msg (verify-request source target opts)]
+ (if-let [error-msg (verify-request source target
+ (:allowed-target-domains config))]
;; respond if request verification failed
{:status 400
:headers {"Content-Type" "application/json; charset=utf-8"}
@@ -64,13 +60,13 @@
;; respond with 201 when Webmention passed checks and
;; was sent into queue, include a Location header
(let [wm-id (string->md5-hex (str source target))
- wm-url (str (get-config :base-url) "/api/mention/" wm-id)
+ wm-url (str (:base-url config) "/api/mention/" wm-id)
response {:status 201
:message "Webmention is accepted and pending for verification."
:url wm-url}]
{:status 201
:headers {"Location" wm-url
"Content-Type" "application/json; charset=utf-8"}
- :body response}))))))
+ :body response})))))