mirror of
https://github.com/penpot/penpot.git
synced 2025-02-03 21:09:00 -05:00
🎉 Add first helpers for manipulate the file data from server repl.
This commit is contained in:
parent
a14a71c222
commit
067aece437
1 changed files with 32 additions and 1 deletions
|
@ -3,4 +3,35 @@
|
||||||
#_:clj-kondo/ignore
|
#_:clj-kondo/ignore
|
||||||
(:require
|
(:require
|
||||||
[clojure.pprint :refer [pprint]]
|
[clojure.pprint :refer [pprint]]
|
||||||
[app.db :as db]))
|
[app.db :as db]
|
||||||
|
[app.common.pages.migrations :as pmg]
|
||||||
|
[app.util.blob :as blob]
|
||||||
|
[app.common.pages :as cp]))
|
||||||
|
|
||||||
|
(defn update-file
|
||||||
|
([id f] (update-file id f false))
|
||||||
|
([id f save?]
|
||||||
|
(db/with-atomic [conn db/pool]
|
||||||
|
(let [file (db/get-by-id conn :file id {:for-update true})
|
||||||
|
file (-> file
|
||||||
|
(update :data app.util.blob/decode)
|
||||||
|
(update :data pmg/migrate-data)
|
||||||
|
(update :data f)
|
||||||
|
(update :data blob/encode)
|
||||||
|
(update :revn inc))]
|
||||||
|
(when save?
|
||||||
|
(db/update! conn :file
|
||||||
|
{:data (:data file)}
|
||||||
|
{:id (:id file)}))
|
||||||
|
(update file :data blob/decode)))))
|
||||||
|
|
||||||
|
(defn update-file-raw
|
||||||
|
[id data]
|
||||||
|
(db/with-atomic [conn db/pool]
|
||||||
|
(db/update! conn :file
|
||||||
|
{:data data}
|
||||||
|
{:id id})))
|
||||||
|
|
||||||
|
;; Examples
|
||||||
|
;; (def backup (update-file #uuid "1586e1f0-3e02-11eb-b1d2-556a2f641513" identity))
|
||||||
|
;; (def x (update-file #uuid "1586e1f0-3e02-11eb-b1d2-556a2f641513" (fn [{:keys [data] :as file}] (update-in data [:pages-index #uuid "878278c0-3ef0-11eb-9d67-8551e7624f43" :objects] dissoc nil))))
|
||||||
|
|
Loading…
Add table
Reference in a new issue