mirror of
https://github.com/penpot/penpot.git
synced 2025-05-20 19:46:11 +02:00
🎉 Add more helpers on srepl ns
This commit is contained in:
parent
c027de2592
commit
a42d7164ad
2 changed files with 40 additions and 4 deletions
|
@ -30,6 +30,8 @@
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
[expound.alpha :as expound]))
|
[expound.alpha :as expound]))
|
||||||
|
|
||||||
|
(def ^:dynamic *conn*)
|
||||||
|
|
||||||
(defn reset-password!
|
(defn reset-password!
|
||||||
"Reset a password to a specific one for a concrete user or all users
|
"Reset a password to a specific one for a concrete user or all users
|
||||||
if email is `:all` keyword."
|
if email is `:all` keyword."
|
||||||
|
@ -69,8 +71,9 @@
|
||||||
(update :features db/decode-pgarray #{})
|
(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)))
|
||||||
file (-> (update-fn file)
|
file (binding [*conn* conn]
|
||||||
(cond-> inc-revn? (update :revn inc)))]
|
(-> (update-fn file)
|
||||||
|
(cond-> inc-revn? (update :revn inc))))]
|
||||||
(when save?
|
(when save?
|
||||||
(let [features (db/create-array conn "text" (:features file))
|
(let [features (db/create-array conn "text" (:features file))
|
||||||
data (blob/encode (:data file))]
|
data (blob/encode (:data file))]
|
||||||
|
|
|
@ -16,7 +16,9 @@
|
||||||
[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.blob :as blob]
|
||||||
[app.util.objects-map :as omap]
|
[app.util.objects-map :as omap]
|
||||||
|
[app.util.pointer-map :as pmap]
|
||||||
[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]))
|
||||||
|
@ -103,12 +105,15 @@
|
||||||
(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
|
|
||||||
|
(defn enable-objects-map-feature-on-file!
|
||||||
[system & {:keys [save? id]}]
|
[system & {:keys [save? id]}]
|
||||||
(letfn [(update-file [{:keys [features] :as file}]
|
(letfn [(update-file [{:keys [features] :as file}]
|
||||||
(if (contains? features "storage/objects-map")
|
(if (contains? features "storage/objects-map")
|
||||||
file
|
file
|
||||||
(update file :data migrate-to-omap)))
|
(-> file
|
||||||
|
(update :data migrate-to-omap)
|
||||||
|
(update :features conj "storage/objects-map"))))
|
||||||
|
|
||||||
(migrate-to-omap [data]
|
(migrate-to-omap [data]
|
||||||
(-> data
|
(-> data
|
||||||
|
@ -119,3 +124,31 @@
|
||||||
:id id
|
:id id
|
||||||
:update-fn update-file
|
:update-fn update-file
|
||||||
:save? save?)))
|
:save? save?)))
|
||||||
|
|
||||||
|
(defn enable-pointer-map-feature-on-file!
|
||||||
|
[system & {:keys [save? id]}]
|
||||||
|
(letfn [(update-file [{:keys [features id] :as file}]
|
||||||
|
(if (contains? features "storage/pointer-map")
|
||||||
|
file
|
||||||
|
(-> file
|
||||||
|
(update :data migrate-to-omap id)
|
||||||
|
(update :features conj "storage/pointer-map"))))
|
||||||
|
|
||||||
|
(migrate-to-omap [data file-id]
|
||||||
|
(binding [pmap/*tracked* (atom {})
|
||||||
|
pmap/*metadata* {:file-id file-id}]
|
||||||
|
(let [data (-> data
|
||||||
|
(update :pages-index update-vals pmap/wrap)
|
||||||
|
(update :components pmap/wrap))]
|
||||||
|
(doseq [[id item] @pmap/*tracked*]
|
||||||
|
(db/insert! h/*conn* :file-data-fragment
|
||||||
|
{:id id
|
||||||
|
:file-id file-id
|
||||||
|
:metadata (-> item meta db/tjson)
|
||||||
|
:content (-> item deref blob/encode)}))
|
||||||
|
data)))]
|
||||||
|
|
||||||
|
(h/update-file! system
|
||||||
|
:id id
|
||||||
|
:update-fn update-file
|
||||||
|
:save? save?)))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue