diff options
| author | eltrac <hi@eltr.ac> | 2026-05-12 10:45:32 +0800 |
|---|---|---|
| committer | eltrac <hi@eltr.ac> | 2026-05-12 10:45:32 +0800 |
| commit | 88594298502531868a7b6b55cfcc899dc2e93ddf (patch) | |
| tree | 18bd9dbeab737df490c8022069aa45acb57fa97d /src | |
| parent | 091573df0455b5e947511c97476577d07fc7134d (diff) | |
refactor(processor): do not depend on config directly
Diffstat (limited to 'src')
| -rw-r--r-- | src/weepinbell/core.clj | 4 | ||||
| -rw-r--r-- | src/weepinbell/processor.clj | 18 | ||||
| -rw-r--r-- | src/weepinbell/wrapper.clj | 11 |
3 files changed, 18 insertions, 15 deletions
diff --git a/src/weepinbell/core.clj b/src/weepinbell/core.clj index a190fa2..85418ee 100644 --- a/src/weepinbell/core.clj +++ b/src/weepinbell/core.clj @@ -27,7 +27,9 @@ (webhook/trigger hook webhooks))) hooks))) ;; plug in storage layer - store) + store + ;; load configuration + (load-config)) ;; Start receiver server ;; Check for a PORT environment variable, default to 3000 (let [port (Integer/parseInt (or (System/getenv "PORT") "3000"))] diff --git a/src/weepinbell/processor.clj b/src/weepinbell/processor.clj index 70d47cb..ce7e476 100644 --- a/src/weepinbell/processor.clj +++ b/src/weepinbell/processor.clj @@ -10,23 +10,23 @@ (defn process-new-webmention "Store new webmention if verifed. Do nothing otherwise." - [source target callbacks storage] + [source target callbacks storage config] (when (verify-mention source target) (timbre/info "\nšāāļø Valid webmention received: \n" "from " source "\n" "to " target "\n\n") - (let [data (wrapper/wrap source target)] + (let [data (wrapper/wrap source target (:base-url config))] ((:append storage) data))) ((:on-create callbacks))) (defn process-existing-webmention "Update existing Webmention when verified, delete it otherwise." - [source target callbacks storage] + [source target callbacks storage config] (timbre/info "Webmention exists.") (if (verify-mention source target) (do ((:update storage) source target - (wrapper/wrap source target)) + (wrapper/wrap source target (:base-url config))) ((:on-update callbacks)) (timbre/info "Webmention updated.")) (do @@ -42,22 +42,22 @@ Callbacks and storage are maps of functions, to avoid depending on technical details directly." - [wm callbacks storage] + [wm callbacks storage config] (let [{:keys [s t]} wm] ;; check if such webmention exists ;; if so, update it or delete it ;; if not, write to data (do (if ((:get storage) s t) - (process-existing-webmention s t callbacks storage) - (process-new-webmention s t callbacks storage)) + (process-existing-webmention s t callbacks storage config) + (process-new-webmention s t callbacks storage config)) ((:on-receive callbacks))))) (defn start "Start a go-loop that recursively calls to process-webmention." - [wmc callbacks storage] + [wmc callbacks storage config] (go-loop [wm (<! wmc)] (timbre/info "Webmention found in queue.") - (process-webmention wm callbacks storage) + (process-webmention wm callbacks storage config) (recur (<! wmc)))) diff --git a/src/weepinbell/wrapper.clj b/src/weepinbell/wrapper.clj index 354e980..ca1789e 100644 --- a/src/weepinbell/wrapper.clj +++ b/src/weepinbell/wrapper.clj @@ -2,7 +2,6 @@ (:require [weepinbell.utils :refer [javamap->map file-exists? download-file]] - [weepinbell.config :refer [get-config]] [weepinbell.microformats-parser :as mf-parser] [taoensso.timbre :as timbre] [md5.core :refer [string->md5-hex]])) @@ -15,7 +14,7 @@ first) (-> mf (get-in [:properties "photo"]) first))) -(defn- proxy-mf-photo [raw-photo] +(defn- proxy-mf-photo [raw-photo base-url] (if raw-photo (let [photo-url (str raw-photo) file-ext (or (re-find #"\.(?:jpg|jpeg|png|gif|webp)" photo-url) ".jpg") @@ -26,12 +25,12 @@ (when-not (file-exists? local-path) (timbre/info "Downloading microformats photo to proxy external image.") (download-file photo-url local-path)) - (str (get-config :base-url) public-path)) + (str base-url public-path)) nil)) (defn wrap "Parse microformats and collect essential info. Wrap source, target and collected data into a Clojure map and return it." - [source target] + [source target base-url] (let [mf (-> source mf-parser/parse javamap->map @@ -41,7 +40,9 @@ :target target :id (string->md5-hex (str source target)) :modified (System/currentTimeMillis)} - proxied-photo (-> mf find-mf-photo proxy-mf-photo)] + proxied-photo (-> mf + find-mf-photo + (proxy-mf-photo base-url))] {:webmention wm :microformats mf :extra {:proxied-photo proxied-photo}})) |
