summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoreltrac <hi@eltr.ac>2026-11-03 11:29:44 +0800
committereltrac <hi@eltr.ac>2026-11-03 11:29:44 +0800
commit5488d2538a41d79328fea0061624a127c7cfe5fd (patch)
treef4eb26f0e916b0dddf1cac65f021ebb2f9140731 /src
parenta6e004f4e9dbfc848fbdf2e8434f23b9d6d738ae (diff)
migration: rehash during migrate-db #81
Diffstat (limited to 'src')
-rw-r--r--src/weepinbell/migration.clj15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/weepinbell/migration.clj b/src/weepinbell/migration.clj
index c59910a..701ed8f 100644
--- a/src/weepinbell/migration.clj
+++ b/src/weepinbell/migration.clj
@@ -6,6 +6,7 @@
[weepinbell.storage.edn-storage :as edns]
[weepinbell.storage.spec]
[weepinbell.metadata.microformats :refer [parse-microformats]]
+ [weepinbell.utils.digest :refer [digest]]
[clojure.java.io :as io]
[fast-edn.core :as edn]))
@@ -18,6 +19,15 @@
(assoc :jf2 (parse-microformats (:microformats wm)))
(dissoc :microformats)))
+(defn rehash
+ "Given a Webmention object, recalculate its hash and return a new map."
+ [wm]
+ {:pre [(map? wm) (contains? wm :webmention)]}
+ (assoc wm :webmention
+ (assoc (:webmention wm) :id
+ (digest (str (get-in wm [:webmention :source])
+ (get-in wm [:webmention :target]))))))
+
(defn edn->h2
"Given an EDN file and a SQLite DB path, migrate data from that
edn file to SQLite DB. It appends data to DB so the destination
@@ -35,7 +45,8 @@
(println "Appending webmention" id "to database")
(try
(let [wm (if (contains? wm :microformats)
- (mf->jf2 wm) wm)]
+ (mf->jf2 wm) wm)
+ wm (rehash wm)]
(h2/insert-webmention ds wm))
(catch Exception e
(println "Something unexpected happened.")
@@ -43,7 +54,7 @@
(println "Done")))
(defn- file? [file]
- (or (string? file)
+ (or (string? file)
(instance? java.io.File file)
(instance? java.net.URL file)))