diff options
| author | eltrac <hi@eltr.ac> | 2026-10-13 21:27:29 +0800 |
|---|---|---|
| committer | eltrac <hi@eltr.ac> | 2026-10-13 21:27:29 +0800 |
| commit | 3989bf6fbbb242ad5bd6a1d1f91f70a6a222f8e2 (patch) | |
| tree | 435dfee792ec80de7b4cfc233efd53fab579529e /src | |
| parent | 29344c41cc11c2d5d34bdfdbcfb8d093fad1002a (diff) | |
style: cljfmt everything
Diffstat (limited to 'src')
| -rw-r--r-- | src/weepinbell/core.clj | 14 | ||||
| -rw-r--r-- | src/weepinbell/http/client.clj | 26 | ||||
| -rw-r--r-- | src/weepinbell/http/downloader.clj | 6 | ||||
| -rw-r--r-- | src/weepinbell/utils/url.clj | 26 | ||||
| -rw-r--r-- | src/weepinbell/webhook.clj | 4 | ||||
| -rw-r--r-- | src/weepinbell/webserver/facade.clj | 4 | ||||
| -rw-r--r-- | src/weepinbell/webserver/retriever.clj | 62 |
7 files changed, 71 insertions, 71 deletions
diff --git a/src/weepinbell/core.clj b/src/weepinbell/core.clj index edc3918..20c0aef 100644 --- a/src/weepinbell/core.clj +++ b/src/weepinbell/core.clj @@ -52,13 +52,13 @@ stop-system (start-system)] ;; Register signal handlers for SIGINT and SIGTERM (doseq [signal ["INT" "TERM"]] - (Signal/handle (Signal. signal) - (reify SignalHandler - (handle [_ sig] - (stop-system) - (timbre/info "signal" (.getName sig) "received." - "gracefully shut down weepinbell.") - (>!! done-chan true))))) + (Signal/handle (Signal. signal) + (reify SignalHandler + (handle [_ sig] + (stop-system) + (timbre/info "signal" (.getName sig) "received." + "gracefully shut down weepinbell.") + (>!! done-chan true))))) ;; block til signal received (<!! done-chan))) diff --git a/src/weepinbell/http/client.clj b/src/weepinbell/http/client.clj index 99514f4..f051d15 100644 --- a/src/weepinbell/http/client.clj +++ b/src/weepinbell/http/client.clj @@ -74,20 +74,20 @@ (let [retryables #{TimeoutException}]
(some #(instance? % error) retryables)))
-(defmacro with-retry
+(defmacro with-retry
"Retry request after failure with backoff, asynchronously."
[times backoff & body]
`(future (loop [~'current-try 0
- ~'backoff ~backoff]
- (let [~'result (try
- (deref ~@body)
- (catch Throwable ~'e {:error ~'e}))]
- (if (and (:error ~'result)
- (retryable? (:error ~'result))
- (< ~'current-try ~times))
- (do
- (timbre/warn "request failed. retry after" ~'backoff "seconds")
- (Thread/sleep (* ~'backoff 1000))
- (recur (inc ~'current-try) (* 2 ~'backoff)))
- ~'result)))))
+ ~'backoff ~backoff]
+ (let [~'result (try
+ (deref ~@body)
+ (catch Throwable ~'e {:error ~'e}))]
+ (if (and (:error ~'result)
+ (retryable? (:error ~'result))
+ (< ~'current-try ~times))
+ (do
+ (timbre/warn "request failed. retry after" ~'backoff "seconds")
+ (Thread/sleep (* ~'backoff 1000))
+ (recur (inc ~'current-try) (* 2 ~'backoff)))
+ ~'result)))))
diff --git a/src/weepinbell/http/downloader.clj b/src/weepinbell/http/downloader.clj index d58501b..3b5bdfb 100644 --- a/src/weepinbell/http/downloader.clj +++ b/src/weepinbell/http/downloader.clj @@ -1,4 +1,4 @@ -(ns weepinbell.http.downloader +(ns weepinbell.http.downloader (:require [taoensso.timbre :as timbre] [clojure.java.io :as io] [weepinbell.http.client :as client])) @@ -14,7 +14,7 @@ (let [response (client/get! url {:as :stream}) status (:status response)] (if (and status (> status 199) (< status 300)) - (do + (do (timbre/info "Downloading [" url "] -> [" dest-path "]") ;; write to output stream (with-open [in (:body response) @@ -22,7 +22,7 @@ (io/copy in out)) (timbre/info "Download success. File size:" (.length file) "bytes") true) - (do + (do (timbre/warn "Download fail. Status: " status) (when-let [error (:error response)] (timbre/error error)))))) diff --git a/src/weepinbell/utils/url.clj b/src/weepinbell/utils/url.clj index 265509c..9b25cd2 100644 --- a/src/weepinbell/utils/url.clj +++ b/src/weepinbell/utils/url.clj @@ -38,26 +38,26 @@ (defn- normlaize-path [^String path*]
(let [path (or path* "")
deslashed (if (and (pos? (count path)) (.endsWith path "/"))
- (subs path 0 (dec (count path)))
+ (subs path 0 (dec (count path)))
path)]
- (str (.normalize (URI. deslashed)))))
+ (str (.normalize (URI. deslashed)))))
(defn- normalize-query [^String query]
(some-> query
- (string/split #"&")
- sort
- (->> (string/join "&"))))
+ (string/split #"&")
+ sort
+ (->> (string/join "&"))))
(defn normalize
"Normalize URL by removing trailing slashes; removing anchor;
replacing . and ..; ordering query params."
[^String url]
- (try
+ (try
(let [base (URI. url)
- scheme (.getScheme base)
- auth (.getAuthority base)
- path (normlaize-path (.getPath base))
- query (normalize-query (.getQuery base))]
+ scheme (.getScheme base)
+ auth (.getAuthority base)
+ path (normlaize-path (.getPath base))
+ query (normalize-query (.getQuery base))]
(str scheme "://" auth path
- (when (seq query) (str "?" query))))
+ (when (seq query) (str "?" query))))
;; fallback to empty string is url is nil
(catch NullPointerException _ "")
;; fallback to original string if syntax is invalid
@@ -66,7 +66,7 @@ (defn url= [& urls]
(apply = (map normalize urls)))
-(defn extract
+(defn extract
"Given plain text. Returns a vector of URLs that appears in it."
[^String text]
{:pre [(string? text)]
@@ -75,7 +75,7 @@ (.linkTypes (EnumSet/of LinkType/URL))
.build)
indexes (->> (.extractLinks extractor text)
- (map (fn [link]
+ (map (fn [link]
[(.getBeginIndex link)
(.getEndIndex link)])))
urls (map #(subs text (first %) (last %)) indexes)]
diff --git a/src/weepinbell/webhook.clj b/src/weepinbell/webhook.clj index ae0d12b..c93b74a 100644 --- a/src/weepinbell/webhook.clj +++ b/src/weepinbell/webhook.clj @@ -8,7 +8,7 @@ [weepinbell.http.client :as client] [weepinbell.webhook-presets :refer [request-presets]])) -(s/def ::hooks-map +(s/def ::hooks-map (s/keys :req-un [::on-create ::on-update ::on-delete ::on-receive])) ;; utilities @@ -73,7 +73,7 @@ (make-request event-key data (:request-fn %)))) doall)) -(def empty-hooks +(def empty-hooks (zipmap [:on-receive :on-create :on-delete :on-update] (repeat 4 (fn [& _])))) (defn make-hooks diff --git a/src/weepinbell/webserver/facade.clj b/src/weepinbell/webserver/facade.clj index 4a7bead..1e93126 100644 --- a/src/weepinbell/webserver/facade.clj +++ b/src/weepinbell/webserver/facade.clj @@ -15,10 +15,10 @@ (defn make-services [] {:post [#(s/valid? :weepinbell.webserver.handler/services %)]} {:gen-feed feed/rss - :receive receiver/receive + :receive receiver/receive :retrieve-by-domain retriever/by-domain :retrieve-by-url retriever/by-url - :retrieve-by-id retriever/by-id + :retrieve-by-id retriever/by-id :retrieve-by-pair retriever/by-st-pair :count-by-domain counter/by-domain :count-by-url counter/by-url}) diff --git a/src/weepinbell/webserver/retriever.clj b/src/weepinbell/webserver/retriever.clj index eac4053..e335bc9 100644 --- a/src/weepinbell/webserver/retriever.clj +++ b/src/weepinbell/webserver/retriever.clj @@ -23,20 +23,20 @@ ;; query list of webmentions -(defn filter-by-mftype +(defn filter-by-mftype [mftype data] - (if (nil? mftype) data - (->> data - (map (fn [item] - [(get-in item [:webmention :target]) - (get item :microformats)])) - (filter (fn [[target mf]] - (->> mf mfsr/use-items - mfsr/find-h-entry - (mfsr/search-mftype target) - (= mftype))))))) + (if (nil? mftype) data + (->> data + (map (fn [item] + [(get-in item [:webmention :target]) + (get item :microformats)])) + (filter (fn [[target mf]] + (->> mf mfsr/use-items + mfsr/find-h-entry + (mfsr/search-mftype target) + (= mftype))))))) -(defn query-list +(defn query-list "Get a list of webmentions by certain filters." {:pre [(s/keys :req-un [::domain ::path ::page ::page-size ::storage ::mftype])]} [opts] @@ -46,14 +46,14 @@ data ((:get-by-domain storage path) domain) data (filter-by-mftype mftype data) pages (vec (partition-all page-size data)) - page-number (if (number? page) page - (- (count pages) 1)) + page-number (if (number? page) page + (- (count pages) 1)) page-selected (get pages page-number) - result (if reduce-mf? (map #(assoc % :microformats - (reduce-mf (get-in % [:webmention :target]) - (:microformats %))) - page-selected) - page-selected)] + result (if reduce-mf? (map #(assoc % :microformats + (reduce-mf (get-in % [:webmention :target]) + (:microformats %))) + page-selected) + page-selected)] (respond-webmention-list-json result))) (defn by-domain @@ -61,9 +61,9 @@ [domain page storage opts] (query-list {:domain domain :path nil - :page page + :page page :page-size default-page-size - :storage storage + :storage storage :mftype (:type opts) :microformats (:microformats opts)})) @@ -73,17 +73,17 @@ (if url (query-list {:domain (get-domain url) :path (get-path url) - :page page + :page page :page-size default-page-size - :storage storage + :storage storage :mftype (:type opts) :microformats (:microformats opts)}) - {:status 400 + {:status 400 :body {:message "Missing URL. Specify target URL whose webmentions you are querying."}})) ;; query one webmention -(defn query-one +(defn query-one "Get one specific webmention by id or by its source and target." [opts] {:post [(s/keys :req-un [::identifiers ::storage ::microformats])]} @@ -91,23 +91,23 @@ reduce-mf? (not= "raw" microformats) data (apply (:get storage) identifiers) result (if (and (:microformats data) reduce-mf?) - (assoc data :microformats - (reduce-mf (get-in (:microformats data) [:webmention :target]) - (:microformats data))) - data)] + (assoc data :microformats + (reduce-mf (get-in (:microformats data) [:webmention :target]) + (:microformats data))) + data)] (respond-webmention-json result))) (defn by-id "Get one specific webmention by ID." [id storage opts] (query-one {:identifiers [id] - :storage storage + :storage storage :microformats (:microformats opts)})) (defn by-st-pair "Get one specific webmention by source and target." [source target storage opts] (query-one {:identifiers [source target] - :storage storage + :storage storage :microformats (:microformats opts)})) |
