summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoreltrac <hi@eltr.ac>2026-03-04 16:54:01 +0800
committereltrac <hi@eltr.ac>2026-03-04 16:54:01 +0800
commit48dff54f4c1fa309d7cf34d96509df12f52576b3 (patch)
treedf728077fc38250d89a080c6f718124ca39d0c27 /src
parentf8bc78a6180a8b44f61281c4b3643f42a169d688 (diff)
refactor: move data structure to wrap-webmention function
Diffstat (limited to 'src')
-rw-r--r--src/weepinbell/processor.clj58
1 files changed, 32 insertions, 26 deletions
diff --git a/src/weepinbell/processor.clj b/src/weepinbell/processor.clj
index 2536dd4..95476b3 100644
--- a/src/weepinbell/processor.clj
+++ b/src/weepinbell/processor.clj
@@ -15,26 +15,32 @@
;; TODO needs to be more robust
(includes? body target)))
+(defn wrap-webmention
+ "Make GET request to source and collect essential data. Wrap source, target and collected data into a Clojure map and return it."
+ [source target]
+ {:type "entry"
+ :author {:type "card"
+ :name nil
+ :photo nil
+ :url nil}
+ :url source
+ :published nil
+ :content {:text nil
+ :html nil}
+ :wm-received (jt/local-date-time)
+ :wm-source source
+ :wm-target target
+ :wm-id nil})
+
(defn process-verified-webmention
"If a webmention is verified, fetch microformats data and store it."
[source target]
- (do
- (println "\nšŸ™‹ā€ā™‚ļø Valid webmention received:")
- (println "from " source)
- (println "to " target "\n"))
- (let [data {:type "entry"
- :author {:type "card"
- :name nil
- :photo nil
- :url nil}
- :url source
- :published nil
- :content {:text nil
- :html nil}
- :wm-received (jt/local-date-time)
- :wm-source source
- :wm-target target
- :wm-id nil}]
+ ;; log
+ (println "\nšŸ™‹ā€ā™‚ļø Valid webmention received:")
+ (println "from " source)
+ (println "to " target "\n")
+ ;; wrap and store data
+ (let [data (wrap-webmention source target)]
(storage/append data)))
(defn process-webmention
@@ -42,13 +48,13 @@
[wmc]
(println "Processor started.")
(go-loop []
- (let [wm (<! wmc)]
- (println "Webmention found in queue.")
- (if wm
- (let [{:keys [s t]} wm]
- (if (verify-mention s t)
- (process-verified-webmention s t)
- (println "Invalid mention")))
- (println "Idling")))
- (recur)))
+ (let [wm (<! wmc)]
+ (println "Webmention found in queue.")
+ (if wm
+ (let [{:keys [s t]} wm]
+ (if (verify-mention s t)
+ (process-verified-webmention s t)
+ (println "Invalid mention")))
+ (println "Idling")))
+ (recur)))