mirror of
https://github.com/penpot/penpot.git
synced 2025-02-03 21:09:00 -05:00
✨ Update srepl helpers
This commit is contained in:
parent
c0eab96253
commit
b2cbb1e60f
2 changed files with 31 additions and 25 deletions
|
@ -66,17 +66,20 @@
|
||||||
(db/with-atomic [conn (:app.db/pool system)]
|
(db/with-atomic [conn (:app.db/pool system)]
|
||||||
(let [file (db/get-by-id conn :file id {:for-update true})
|
(let [file (db/get-by-id conn :file id {:for-update true})
|
||||||
file (-> file
|
file (-> file
|
||||||
|
(update :features db/decode-pgarray #{})
|
||||||
(update :data blob/decode)
|
(update :data blob/decode)
|
||||||
(cond-> migrate? (update :data pmg/migrate-data))
|
(cond-> migrate? (update :data pmg/migrate-data)))
|
||||||
(update :data update-fn)
|
file (-> (update-fn file)
|
||||||
(update :data blob/encode)
|
|
||||||
(cond-> inc-revn? (update :revn inc)))]
|
(cond-> inc-revn? (update :revn inc)))]
|
||||||
(when save?
|
(when save?
|
||||||
|
(let [features (db/create-array conn "text" (:features file))
|
||||||
|
data (blob/encode (:data file))]
|
||||||
(db/update! conn :file
|
(db/update! conn :file
|
||||||
{:data (:data file)
|
{:data data
|
||||||
:revn (:revn file)}
|
:revn (:revn file)
|
||||||
{:id (:id file)}))
|
:features features}
|
||||||
(update file :data blob/decode))))
|
{:id id})))
|
||||||
|
file)))
|
||||||
|
|
||||||
(def ^:private sql:retrieve-files-chunk
|
(def ^:private sql:retrieve-files-chunk
|
||||||
"SELECT id, name, created_at, data FROM file
|
"SELECT id, name, created_at, data FROM file
|
||||||
|
@ -122,27 +125,12 @@
|
||||||
(on-end state)
|
(on-end state)
|
||||||
state))))))
|
state))))))
|
||||||
|
|
||||||
|
|
||||||
(defn analyze-file-data
|
|
||||||
[system & {:keys [id on-form on-data]}]
|
|
||||||
(let [file (get-file system id)]
|
|
||||||
(cond
|
|
||||||
(fn? on-data)
|
|
||||||
(on-data (:data file))
|
|
||||||
|
|
||||||
(fn? on-form)
|
|
||||||
(walk/postwalk (fn [form]
|
|
||||||
(on-form form)
|
|
||||||
form)
|
|
||||||
(:data file)))
|
|
||||||
nil))
|
|
||||||
|
|
||||||
(defn update-pages
|
(defn update-pages
|
||||||
"Apply a function to all pages of one file. The function receives a page and returns an updated page."
|
"Apply a function to all pages of one file. The function receives a page and returns an updated page."
|
||||||
[data f]
|
[data f]
|
||||||
(update data :pages-index d/update-vals f))
|
(update data :pages-index update-vals f))
|
||||||
|
|
||||||
(defn update-shapes
|
(defn update-shapes
|
||||||
"Apply a function to all shapes of one page The function receives a shape and returns an updated shape"
|
"Apply a function to all shapes of one page The function receives a shape and returns an updated shape"
|
||||||
[page f]
|
[page f]
|
||||||
(update page :objects d/update-vals f))
|
(update page :objects update-vals f))
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
[app.rpc.queries.profile :as profile]
|
[app.rpc.queries.profile :as profile]
|
||||||
[app.srepl.fixes :as f]
|
[app.srepl.fixes :as f]
|
||||||
[app.srepl.helpers :as h]
|
[app.srepl.helpers :as h]
|
||||||
|
[app.util.objects-map :as omap]
|
||||||
[app.util.time :as dt]
|
[app.util.time :as dt]
|
||||||
[clojure.pprint :refer [pprint]]
|
[clojure.pprint :refer [pprint]]
|
||||||
[cuerdas.core :as str]))
|
[cuerdas.core :as str]))
|
||||||
|
@ -101,3 +102,20 @@
|
||||||
(db/update! conn :profile {:is-blocked true} {:id (:id profile)})
|
(db/update! conn :profile {:is-blocked true} {:id (:id profile)})
|
||||||
(db/delete! conn :http-session {:profile-id (:id profile)})
|
(db/delete! conn :http-session {:profile-id (:id profile)})
|
||||||
:blocked))))
|
:blocked))))
|
||||||
|
|
||||||
|
(defn enable-objects-map-on-file
|
||||||
|
[system & {:keys [save? id]}]
|
||||||
|
(letfn [(update-file [{:keys [features] :as file}]
|
||||||
|
(if (contains? features "storage/objects-map")
|
||||||
|
file
|
||||||
|
(update file :data migrate-to-omap)))
|
||||||
|
|
||||||
|
(migrate-to-omap [data]
|
||||||
|
(-> data
|
||||||
|
(update :pages-index update-vals #(update % :objects omap/wrap))
|
||||||
|
(update :components update-vals #(update % :objects omap/wrap))))]
|
||||||
|
|
||||||
|
(h/update-file! system
|
||||||
|
:id id
|
||||||
|
:update-fn update-file
|
||||||
|
:save? save?)))
|
||||||
|
|
Loading…
Add table
Reference in a new issue