From 4c6433b0f18d7fa3f90e3611d744337f5e161808 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 30 Mar 2022 14:38:36 +0200 Subject: [PATCH] :sparkles: Improve migration 14 Remove frame thumbnail if the migration modifies a shape. --- common/src/app/common/pages/migrations.cljc | 33 +++++++++++++-------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/common/src/app/common/pages/migrations.cljc b/common/src/app/common/pages/migrations.cljc index 5f0723250..e7a26ad8e 100644 --- a/common/src/app/common/pages/migrations.cljc +++ b/common/src/app/common/pages/migrations.cljc @@ -304,19 +304,28 @@ (defmethod migrate 14 [data] - (letfn [(update-object [_ {:keys [type] :as object}] - (if (= :image type) - (let [fill-color (str/upper (:fill-color object)) - fill-opacity (:fill-opacity object)] - (cond-> object - (and (= 1 fill-opacity) - (or (= "#B1B2B5" fill-color) - (= "#7B7D85" fill-color))) - (dissoc :fill-color :fill-opacity))) - object)) + (letfn [(process-shape [shape] + (let [fill-color (str/upper (:fill-color shape)) + fill-opacity (:fill-opacity shape)] + (cond-> shape + (and (= 1 fill-opacity) + (or (= "#B1B2B5" fill-color) + (= "#7B7D85" fill-color))) + (dissoc :fill-color :fill-opacity)))) - (update-container [_ container] - (update container :objects #(d/mapm update-object %)))] + (update-container [_ {:keys [objects] :as container}] + (loop [objects objects + shapes (->> (vals objects) + (filter #(= :image (:type %))))] + (if-let [shape (first shapes)] + (let [{:keys [id frame-id] :as shape'} (process-shape shape)] + (if (identical? shape shape') + (recur objects (rest shapes)) + (recur (-> objects + (assoc id shape') + (d/update-when frame-id dissoc :thumbnail)) + (rest shapes)))) + (assoc container :objects objects))))] (-> data (update :pages-index #(d/mapm update-container %))