diff options
| author | eltrac <hi@eltr.ac> | 2026-09-16 10:11:07 +0800 |
|---|---|---|
| committer | eltrac <hi@eltr.ac> | 2026-09-16 10:11:07 +0800 |
| commit | d54b08ee4139de3bf373b21be5e662970e18e586 (patch) | |
| tree | b779d5b963219b6702e4e553810f5f9192d6bff6 /src | |
| parent | f2a9bf15a35cea1d7c3d1a3b2ad1cb809a9daf85 (diff) | |
style: format the codebase
starting from now, every commit should be cljfmt-fixed
Diffstat (limited to 'src')
| -rw-r--r-- | src/weepinbell/handler.clj | 40 | ||||
| -rw-r--r-- | src/weepinbell/http/client.clj | 14 | ||||
| -rw-r--r-- | src/weepinbell/receiver.clj | 38 | ||||
| -rw-r--r-- | src/weepinbell/retriever.clj | 10 | ||||
| -rw-r--r-- | src/weepinbell/utils/digest.clj | 10 | ||||
| -rw-r--r-- | src/weepinbell/utils/url.clj | 2 | ||||
| -rw-r--r-- | src/weepinbell/verifier.clj | 8 | ||||
| -rw-r--r-- | src/weepinbell/webhook.clj | 18 | ||||
| -rw-r--r-- | src/weepinbell/wrapper.clj | 4 |
9 files changed, 72 insertions, 72 deletions
diff --git a/src/weepinbell/handler.clj b/src/weepinbell/handler.clj index 16b19f8..b4b9576 100644 --- a/src/weepinbell/handler.clj +++ b/src/weepinbell/handler.clj @@ -13,36 +13,36 @@ (defmacro defmention-routes [base-path mention-type storage] `(context ~base-path [] - (GET "/" [~'url ~'page] - (retriever/by-url ~'url ~mention-type ~'page ~storage)) - (GET "/:domain" [~'domain ~'page] - (retriever/by-domain ~'domain ~mention-type ~'page ~storage)))) + (GET "/" [~'url ~'page] + (retriever/by-url ~'url ~mention-type ~'page ~storage)) + (GET "/:domain" [~'domain ~'page] + (retriever/by-domain ~'domain ~mention-type ~'page ~storage)))) (defn api-routes [wmc storage config] (routes - (GET "/" [target] (ui/home (:allowed-target-domains config) - (:endpoint config) - target)) + (GET "/" [target] (ui/home (:allowed-target-domains config) + (:endpoint config) + target)) ;; receiver endpoint - (POST (:endpoint config) [source target] - (receive {:s source :t target} wmc config)) + (POST (:endpoint config) [source target] + (receive {:s source :t target} wmc config)) ;; query API routes - (context "/api" [] + (context "/api" [] ;; query webmention list - (defmention-routes "/mentions" nil storage) - (defmention-routes "/likes" :like storage) - (defmention-routes "/reposts" :repost storage) - (defmention-routes "/replies" :reply storage) + (defmention-routes "/mentions" nil storage) + (defmention-routes "/likes" :like storage) + (defmention-routes "/reposts" :repost storage) + (defmention-routes "/replies" :reply storage) ;; query one specific webmention - (context "/mention" [] - (GET "/:id" [id] (retriever/by-id id storage)) - (GET "/" [source target] (retriever/by-st-pair source target storage)))) + (context "/mention" [] + (GET "/:id" [id] (retriever/by-id id storage)) + (GET "/" [source target] (retriever/by-st-pair source target storage)))) ;; RSS feed - (GET "/feed/:domain" [domain] (feed/rss domain storage config)) + (GET "/feed/:domain" [domain] (feed/rss domain storage config)) ;; host proxied avatars (microformats photos) - (route/files "/avatars/" {:root "data/avatars"}) + (route/files "/avatars/" {:root "data/avatars"}) ;; 404 - (route/not-found "Not Found"))) + (route/not-found "Not Found"))) (defn app [wmc storage config] (when (= :clojure.spec.alpha/invalid storage) diff --git a/src/weepinbell/http/client.clj b/src/weepinbell/http/client.clj index 34cd458..7a3bc06 100644 --- a/src/weepinbell/http/client.clj +++ b/src/weepinbell/http/client.clj @@ -6,7 +6,7 @@ (:refer-clojure :exclude [get])
(:require [org.httpkit.client :as hk]))
-(def default-options
+(def default-options
{:user-agent "WebmentionBot"
:timeout 15000})
@@ -17,25 +17,25 @@ (defn- wrap-promise [promised-response]
(future (wrap-response @promised-response)))
-(defn post
+(defn post
"Sends POST request asynchronously. Returns a promise/future."
([url]
(post url nil))
([url options]
(post url options nil))
([url options callbacks]
- (-> url
+ (-> url
(hk/post (merge default-options options) callbacks)
wrap-promise)))
-(defn get
+(defn get
"Sends GET request asynchronously. Returns a promise/future."
([url]
(get url nil))
([url options]
(get url options nil))
([url options callbacks]
- (-> url
+ (-> url
(hk/get (merge default-options options) callbacks)
wrap-promise)))
@@ -48,7 +48,7 @@ ([url options callbacks]
@(get url options callbacks)))
-(defn head
+(defn head
"Sends HEAD request asynchronously. Returns a promise/future."
([url]
(head url nil))
@@ -59,7 +59,7 @@ (hk/head (merge default-options options) callbacks)
wrap-promise)))
-(defn head!
+(defn head!
"Sends HEAD request synchronously. Returns a response."
([url]
@(head url nil))
diff --git a/src/weepinbell/receiver.clj b/src/weepinbell/receiver.clj index b805e43..a0779dd 100644 --- a/src/weepinbell/receiver.clj +++ b/src/weepinbell/receiver.clj @@ -6,7 +6,7 @@ [weepinbell.utils.digest :refer [digest]])) ;; utilities -(defn- remove-anchor +(defn- remove-anchor "Takes a URL string. Removes anchor (#...)" [url] (string/replace url #"#.*" "")) @@ -48,16 +48,16 @@ new-wm {:s source :t target} allowed-domains (:allowed-target-domains config)] ;; Request verification - (if-let [error-msg (verify-request source - target - allowed-domains)] + (if-let [error-msg (verify-request source + target + allowed-domains)] ;; respond if request verification failed - {:status 400 - :headers {"Content-Type" "application/json; charset=utf-8"} - :body {:status 400 - :message error-msg}} + {:status 400 + :headers {"Content-Type" "application/json; charset=utf-8"} + :body {:status 400 + :message error-msg}} ;; proceed if request is ok - (do + (do ;; The receiver SHOULD check that target is a valid ;; resource for which it can accept Webmentions. ;; This check SHOULD happen synchronously to reject @@ -65,17 +65,17 @@ ;; ;; Webmention verification SHOULD be handled asynchronously ;; to prevent DoS (Denial of Service) attacks. - (put! wmc new-wm) + (put! wmc new-wm) ;; respond with 201 when Webmention passed checks and ;; was sent into queue, include a Location header - (let [wm-id (digest (str source target)) - 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}))))) + (let [wm-id (digest (str source target)) + 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}))))) diff --git a/src/weepinbell/retriever.clj b/src/weepinbell/retriever.clj index 1bcd959..e01c9d3 100644 --- a/src/weepinbell/retriever.clj +++ b/src/weepinbell/retriever.clj @@ -26,8 +26,8 @@ (if data (assoc base-resp :body data) (-> base-resp - (assoc :status 400) - (assoc :body "The requested webmention does not exist."))))) + (assoc :status 400) + (assoc :body "The requested webmention does not exist."))))) (defn- respond-webmention-list-json [data] (let [base-resp {:status 200 @@ -36,8 +36,8 @@ (if data (assoc base-resp :body data) (-> base-resp - (assoc :status 400) - (assoc :body {:message "The list is empty, something is wrong with your request."}))))) + (assoc :status 400) + (assoc :body {:message "The list is empty, something is wrong with your request."}))))) (defn- wrap-response-object [data] (let [result {:webmention (:webmention data)}] @@ -79,7 +79,7 @@ [url typ page storage] (if url (cond->> (get-domain url) - true ((:get-by-domain storage)) + true ((:get-by-domain storage)) true (filter #(= url (get-in % [:webmention :target]))) true wrap-response-list typ (filter-response-by-mftype typ) diff --git a/src/weepinbell/utils/digest.clj b/src/weepinbell/utils/digest.clj index 1e894f9..c522103 100644 --- a/src/weepinbell/utils/digest.clj +++ b/src/weepinbell/utils/digest.clj @@ -1,13 +1,13 @@ -(ns weepinbell.utils.digest
+(ns weepinbell.utils.digest
(:import java.security.MessageDigest)
(:require [clojure.string :refer [upper-case]]))
-(defn- java-digest [^String s algo]
- (let [algorithm (MessageDigest/getInstance algo)
- raw-bytes (.digest algorithm (.getBytes s "UTF-8"))]
+(defn- java-digest [^String s algo]
+ (let [algorithm (MessageDigest/getInstance algo)
+ raw-bytes (.digest algorithm (.getBytes s "UTF-8"))]
(apply str (map #(format "%02x" %) raw-bytes))))
-(defn digest
+(defn digest
([s]
(digest s :sha-256 32))
([s algo]
diff --git a/src/weepinbell/utils/url.clj b/src/weepinbell/utils/url.clj index 1e47b82..5fe2b78 100644 --- a/src/weepinbell/utils/url.clj +++ b/src/weepinbell/utils/url.clj @@ -3,7 +3,7 @@ (:require [clojure.string :as string]))
(defn valid-http-url? [url-string]
- (try
+ (try
(let [url (URL. url-string)
uri (.toURI url)
scheme (.getScheme uri)
diff --git a/src/weepinbell/verifier.clj b/src/weepinbell/verifier.clj index bd18205..06bf3fc 100644 --- a/src/weepinbell/verifier.clj +++ b/src/weepinbell/verifier.clj @@ -25,12 +25,12 @@ (let [{:keys [status body headers error]} (client/get! source {:headers {"Range" "bytes=0-1048575"}}) target-headers (:headers (client/head! target)) id (digest-short (str source target))] - (timbre/info "verifying webmention" id + (timbre/info "verifying webmention" id (str "(" "source: " source ", target: " target ")")) - (cond + (cond ;; handle error - error - (do + error + (do (timbre/error "error verifying webmention:" error) false) ;; verify HTTP status diff --git a/src/weepinbell/webhook.clj b/src/weepinbell/webhook.clj index c084f47..6ff532d 100644 --- a/src/weepinbell/webhook.clj +++ b/src/weepinbell/webhook.clj @@ -5,13 +5,13 @@ (defn- send-webhook [url] (client/post url - {:timeout 15000} - (fn async-callback [{:keys [status _ _ error]}] - (cond - error (timbre/error "error ocurred sending webhook to" url ":" error) - (>= status 500) (timbre/error "something's wrong with webhook server of" url) - (>= status 400) (timbre/error "webhook url is invalid:" url) - :else (timbre/info "request sent to" url))))) + {:timeout 15000} + (fn async-callback [{:keys [status _ _ error]}] + (cond + error (timbre/error "error ocurred sending webhook to" url ":" error) + (>= status 500) (timbre/error "something's wrong with webhook server of" url) + (>= status 400) (timbre/error "webhook url is invalid:" url) + :else (timbre/info "request sent to" url))))) (defn trigger "Send requests to a list of webhooks. @@ -20,12 +20,12 @@ ([urls] (trigger urls nil)) ([keyw-or-urls webhooks] - (when-let [hooks (if (nil? webhooks) + (when-let [hooks (if (nil? webhooks) keyw-or-urls (->> (get webhooks keyw-or-urls) (filter string?) (filter valid-http-url?)))] - (when (keyword? keyw-or-urls) + (when (keyword? keyw-or-urls) (timbre/info "Webhook" (name keyw-or-urls) "triggered.")) (->> hooks (map send-webhook) doall)))) diff --git a/src/weepinbell/wrapper.clj b/src/weepinbell/wrapper.clj index e013f6d..0bf3496 100644 --- a/src/weepinbell/wrapper.clj +++ b/src/weepinbell/wrapper.clj @@ -40,8 +40,8 @@ :target target :id (digest (str source target)) :modified (System/currentTimeMillis)} - proxied-photo (-> mf - find-mf-photo + proxied-photo (-> mf + find-mf-photo (proxy-mf-photo base-url))] {:webmention wm :microformats mf |
