mirror of
https://github.com/penpot/penpot.git
synced 2025-05-12 10:56:38 +02:00
🐛 Properly handle storage features on binfile import
This commit is contained in:
parent
3280a6853e
commit
523539e403
2 changed files with 55 additions and 26 deletions
|
@ -9,6 +9,7 @@
|
||||||
(:require
|
(:require
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.exceptions :as ex]
|
[app.common.exceptions :as ex]
|
||||||
|
[app.common.files.features :as ffeat]
|
||||||
[app.common.logging :as l]
|
[app.common.logging :as l]
|
||||||
[app.common.pages.migrations :as pmg]
|
[app.common.pages.migrations :as pmg]
|
||||||
[app.common.spec :as us]
|
[app.common.spec :as us]
|
||||||
|
@ -28,6 +29,7 @@
|
||||||
[app.tasks.file-gc]
|
[app.tasks.file-gc]
|
||||||
[app.util.blob :as blob]
|
[app.util.blob :as blob]
|
||||||
[app.util.fressian :as fres]
|
[app.util.fressian :as fres]
|
||||||
|
[app.util.objects-map :as omap]
|
||||||
[app.util.pointer-map :as pmap]
|
[app.util.pointer-map :as pmap]
|
||||||
[app.util.services :as sv]
|
[app.util.services :as sv]
|
||||||
[app.util.time :as dt]
|
[app.util.time :as dt]
|
||||||
|
@ -609,12 +611,23 @@
|
||||||
(vswap! *state* update :index update-index files)
|
(vswap! *state* update :index update-index files)
|
||||||
(vswap! *state* assoc :version version :files files)))
|
(vswap! *state* assoc :version version :files files)))
|
||||||
|
|
||||||
|
(defn- postprocess-file
|
||||||
|
[data]
|
||||||
|
(let [omap-wrap ffeat/*wrap-with-objects-map-fn*
|
||||||
|
pmap-wrap ffeat/*wrap-with-pointer-map-fn*]
|
||||||
|
(-> data
|
||||||
|
(update :pages-index update-vals #(update % :objects omap-wrap))
|
||||||
|
(update :pages-index update-vals pmap-wrap)
|
||||||
|
(update :components update-vals #(update % :objects omap-wrap))
|
||||||
|
(update :components pmap-wrap))))
|
||||||
|
|
||||||
(defmethod read-section :v1/files
|
(defmethod read-section :v1/files
|
||||||
[{:keys [conn ::input ::migrate? ::project-id ::timestamp ::overwrite?]}]
|
[{:keys [conn ::input ::migrate? ::project-id ::timestamp ::overwrite?]}]
|
||||||
(doseq [expected-file-id (-> *state* deref :files)]
|
(doseq [expected-file-id (-> *state* deref :files)]
|
||||||
(let [file (read-obj! input)
|
(let [file (read-obj! input)
|
||||||
media' (read-obj! input)
|
media' (read-obj! input)
|
||||||
file-id (:id file)]
|
file-id (:id file)
|
||||||
|
features files/default-features]
|
||||||
|
|
||||||
(when (not= file-id expected-file-id)
|
(when (not= file-id expected-file-id)
|
||||||
(ex/raise :type :validation
|
(ex/raise :type :validation
|
||||||
|
@ -629,33 +642,42 @@
|
||||||
(l/debug :hint "update media references" ::l/async false)
|
(l/debug :hint "update media references" ::l/async false)
|
||||||
(vswap! *state* update :media into (map #(update % :id lookup-index)) media')
|
(vswap! *state* update :media into (map #(update % :id lookup-index)) media')
|
||||||
|
|
||||||
(l/debug :hint "processing file" :file-id file-id ::l/async false)
|
(l/debug :hint "processing file" :file-id file-id ::features features ::l/async false)
|
||||||
|
|
||||||
(let [file-id' (lookup-index file-id)
|
(binding [ffeat/*current* features
|
||||||
data (-> (:data file)
|
ffeat/*wrap-with-objects-map-fn* (if (features "storage/objects-map") omap/wrap identity)
|
||||||
(assoc :id file-id')
|
ffeat/*wrap-with-pointer-map-fn* (if (features "storage/pointer-map") pmap/wrap identity)
|
||||||
(cond-> migrate? (pmg/migrate-data))
|
pmap/*tracked* (atom {})]
|
||||||
(update :pages-index relink-shapes)
|
|
||||||
(update :components relink-shapes)
|
|
||||||
(update :media relink-media))
|
|
||||||
|
|
||||||
params {:id file-id'
|
(let [file-id' (lookup-index file-id)
|
||||||
:project-id project-id
|
data (-> (:data file)
|
||||||
:name (:name file)
|
(assoc :id file-id')
|
||||||
:revn (:revn file)
|
(cond-> migrate? (pmg/migrate-data))
|
||||||
:is-shared (:is-shared file)
|
(update :pages-index relink-shapes)
|
||||||
:data (blob/encode data)
|
(update :components relink-shapes)
|
||||||
:created-at timestamp
|
(update :media relink-media)
|
||||||
:modified-at timestamp}]
|
(postprocess-file))
|
||||||
|
|
||||||
(l/debug :hint "create file" :id file-id' ::l/async false)
|
params {:id file-id'
|
||||||
|
:project-id project-id
|
||||||
|
:features (db/create-array conn "text" features)
|
||||||
|
:name (:name file)
|
||||||
|
:revn (:revn file)
|
||||||
|
:is-shared (:is-shared file)
|
||||||
|
:data (blob/encode data)
|
||||||
|
:created-at timestamp
|
||||||
|
:modified-at timestamp}]
|
||||||
|
|
||||||
(if overwrite?
|
(l/debug :hint "create file" :id file-id' ::l/async false)
|
||||||
(create-or-update-file conn params)
|
|
||||||
(db/insert! conn :file params))
|
|
||||||
|
|
||||||
(when overwrite?
|
(if overwrite?
|
||||||
(db/delete! conn :file-thumbnail {:file-id file-id'}))))))
|
(create-or-update-file conn params)
|
||||||
|
(db/insert! conn :file params))
|
||||||
|
|
||||||
|
(files/persist-pointers! conn file-id')
|
||||||
|
|
||||||
|
(when overwrite?
|
||||||
|
(db/delete! conn :file-thumbnail {:file-id file-id'})))))))
|
||||||
|
|
||||||
(defmethod read-section :v1/rels
|
(defmethod read-section :v1/rels
|
||||||
[{:keys [conn ::input ::timestamp]}]
|
[{:keys [conn ::input ::timestamp]}]
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
[app.common.spec :as us]
|
[app.common.spec :as us]
|
||||||
[app.common.types.file :as ctf]
|
[app.common.types.file :as ctf]
|
||||||
[app.common.types.shape-tree :as ctt]
|
[app.common.types.shape-tree :as ctt]
|
||||||
|
[app.config :as cf]
|
||||||
[app.db :as db]
|
[app.db :as db]
|
||||||
[app.db.sql :as sql]
|
[app.db.sql :as sql]
|
||||||
[app.loggers.audit :as-alias audit]
|
[app.loggers.audit :as-alias audit]
|
||||||
|
@ -43,7 +44,13 @@
|
||||||
"storage/pointer-map"
|
"storage/pointer-map"
|
||||||
"components/v2"})
|
"components/v2"})
|
||||||
|
|
||||||
(def default-features #{})
|
(def default-features
|
||||||
|
(cond-> #{}
|
||||||
|
(contains? cf/flags :fdata-storage-pointer-map)
|
||||||
|
(conj "storage/pointer-map")
|
||||||
|
|
||||||
|
(contains? cf/flags :fdata-storage-objects-map)
|
||||||
|
(conj "storage/objects-map")))
|
||||||
|
|
||||||
;; --- SPECS
|
;; --- SPECS
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue