summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoreltrac <hi@eltr.ac>2026-09-11 11:19:15 +0800
committereltrac <hi@eltr.ac>2026-09-11 11:19:15 +0800
commit5dbd5d843bdb3d0ad30605f15c3b71990cae2b33 (patch)
tree195d012c09bc3957b258e33bc7e31f919c09e0ed /src
parent468a3649d970ccfd8f5c8d5c0c70e970c9630f93 (diff)
refactor(receiver, wrapper, feed): replace md5-hash dependency #9
use Java introp instead of cljc-md5, which is heavy on dependencies.
Diffstat (limited to 'src')
-rw-r--r--src/weepinbell/feed.clj4
-rw-r--r--src/weepinbell/receiver.clj4
-rw-r--r--src/weepinbell/utils/digest.clj7
-rw-r--r--src/weepinbell/wrapper.clj6
4 files changed, 14 insertions, 7 deletions
diff --git a/src/weepinbell/feed.clj b/src/weepinbell/feed.clj
index 18cadfa..c28e0f9 100644
--- a/src/weepinbell/feed.clj
+++ b/src/weepinbell/feed.clj
@@ -1,14 +1,14 @@
(ns weepinbell.feed
(:require [clj-rss.core :as rss]
[weepinbell.utils :refer [get-domain]]
- [md5.core :refer [string->md5-hex]])
+ [weepinbell.utils.digest :refer [md5-hash]])
(:import [java.time Instant]))
(defn make-feed-items [wms config]
(->> wms
(map #(let [wm (:webmention %)
id (if-let [id (:id wm)] id
- (string->md5-hex (str (:source wm) (:target wm))))
+ (md5-hash (str (:source wm) (:target wm))))
permalink (str (:base-url config) "/api/mention/" id)
modified (:modified wm)
pub-date (when modified
diff --git a/src/weepinbell/receiver.clj b/src/weepinbell/receiver.clj
index 0eee92c..21433ee 100644
--- a/src/weepinbell/receiver.clj
+++ b/src/weepinbell/receiver.clj
@@ -3,7 +3,7 @@
(:require [clojure.string :as string]
[clojure.core.async :refer [put!]]
[weepinbell.utils :refer [valid-http-url? get-domain]]
- [md5.core :refer [string->md5-hex]]))
+ [weepinbell.utils.digest :refer [md5-hash]]))
;; utilities
(defn- remove-anchor
@@ -68,7 +68,7 @@
(put! wmc new-wm)
;; 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))
+ (let [wm-id (md5-hash (str source target))
wm-url (str (:base-url config) "/api/mention/" wm-id)
response {:status 201
:message "Webmention is accepted and pending for verification."
diff --git a/src/weepinbell/utils/digest.clj b/src/weepinbell/utils/digest.clj
new file mode 100644
index 0000000..979c547
--- /dev/null
+++ b/src/weepinbell/utils/digest.clj
@@ -0,0 +1,7 @@
+(ns weepinbell.utils.digest
+ (:import java.security.MessageDigest))
+
+(defn md5-hash [^String s]
+ (let [algorithm (MessageDigest/getInstance "MD5")
+ raw-bytes (.digest algorithm (.getBytes s "UTF-8"))]
+ (apply str (map #(format "%02x" %) raw-bytes))))
diff --git a/src/weepinbell/wrapper.clj b/src/weepinbell/wrapper.clj
index ca1789e..a3659e7 100644
--- a/src/weepinbell/wrapper.clj
+++ b/src/weepinbell/wrapper.clj
@@ -4,7 +4,7 @@
download-file]]
[weepinbell.microformats-parser :as mf-parser]
[taoensso.timbre :as timbre]
- [md5.core :refer [string->md5-hex]]))
+ [weepinbell.utils.digest :refer [md5-hash]]))
(defn- find-mf-photo [mf]
(or (-> mf
@@ -18,7 +18,7 @@
(if raw-photo
(let [photo-url (str raw-photo)
file-ext (or (re-find #"\.(?:jpg|jpeg|png|gif|webp)" photo-url) ".jpg")
- filename (str (string->md5-hex photo-url) file-ext)
+ filename (str (md5-hash photo-url) file-ext)
local-path (str "data/avatars/" filename)
public-path (str "/avatars/" filename)]
;; download photo if not exists
@@ -38,7 +38,7 @@
javamap->map)
wm {:source source
:target target
- :id (string->md5-hex (str source target))
+ :id (md5-hash (str source target))
:modified (System/currentTimeMillis)}
proxied-photo (-> mf
find-mf-photo