mirror of
https://github.com/penpot/penpot.git
synced 2025-06-27 15:46:59 +02:00
🐛 Fix some edge cases on feature handling on binfile import process
This commit is contained in:
parent
eee28a5793
commit
47baa21d53
1 changed files with 46 additions and 42 deletions
|
@ -11,7 +11,7 @@
|
||||||
[app.common.exceptions :as ex]
|
[app.common.exceptions :as ex]
|
||||||
[app.common.features :as cfeat]
|
[app.common.features :as cfeat]
|
||||||
[app.common.files.defaults :as cfd]
|
[app.common.files.defaults :as cfd]
|
||||||
[app.common.files.migrations :as pmg]
|
[app.common.files.migrations :as fmg]
|
||||||
[app.common.files.validate :as fval]
|
[app.common.files.validate :as fval]
|
||||||
[app.common.fressian :as fres]
|
[app.common.fressian :as fres]
|
||||||
[app.common.logging :as l]
|
[app.common.logging :as l]
|
||||||
|
@ -701,23 +701,28 @@
|
||||||
(update :object-id #(str/replace-first % #"^(.*?)/" (str file-id "/")))))
|
(update :object-id #(str/replace-first % #"^(.*?)/" (str file-id "/")))))
|
||||||
thumbnails))
|
thumbnails))
|
||||||
|
|
||||||
(defn- process-fdata
|
(defn- process-file
|
||||||
[fdata id]
|
[{:keys [id] :as file}]
|
||||||
(-> fdata
|
(-> file
|
||||||
(dissoc :recent-colors)
|
(update :data (fn [fdata]
|
||||||
(assoc :id id)
|
(-> fdata
|
||||||
(cond-> (> (:version fdata) cfd/version)
|
(assoc :id id)
|
||||||
(assoc :version cfd/version))
|
(dissoc :recent-colors)
|
||||||
;; FIXME: We're temporarily activating all
|
(cond-> (> (:version fdata) cfd/version)
|
||||||
;; migrations because a problem in the
|
(assoc :version cfd/version))
|
||||||
;; environments messed up with the version
|
;; FIXME: We're temporarily activating all
|
||||||
;; numbers When this problem is fixed delete
|
;; migrations because a problem in the
|
||||||
;; the following line
|
;; environments messed up with the version
|
||||||
(assoc :version 22)
|
;; numbers When this problem is fixed delete
|
||||||
(pmg/migrate-data)
|
;; the following line
|
||||||
(update :pages-index relink-shapes)
|
(cond-> (> (:version fdata) 22)
|
||||||
(update :components relink-shapes)
|
(assoc :version 22)))))
|
||||||
(update :media relink-media)))
|
(fmg/migrate-file)
|
||||||
|
(update :data (fn [fdata]
|
||||||
|
(-> fdata
|
||||||
|
(update :pages-index relink-shapes)
|
||||||
|
(update :components relink-shapes)
|
||||||
|
(update :media relink-media))))))
|
||||||
|
|
||||||
|
|
||||||
(defmethod read-section :v1/files
|
(defmethod read-section :v1/files
|
||||||
|
@ -730,19 +735,7 @@
|
||||||
file-id (:id file)
|
file-id (:id file)
|
||||||
file-id' (lookup-index file-id)
|
file-id' (lookup-index file-id)
|
||||||
|
|
||||||
thumbnails (:thumbnails file)
|
thumbnails (:thumbnails file)]
|
||||||
file (update file :features cfeat/migrate-legacy-features)
|
|
||||||
|
|
||||||
features (-> enabled-features
|
|
||||||
(set/difference cfeat/frontend-only-features)
|
|
||||||
(set/union (cfeat/check-supported-features! (:features file))))]
|
|
||||||
|
|
||||||
;; All features that are enabled and requires explicit migration
|
|
||||||
;; are added to the state for a posterior migration step
|
|
||||||
(doseq [feature (-> enabled-features
|
|
||||||
(set/difference cfeat/no-migration-features)
|
|
||||||
(set/difference (:features file)))]
|
|
||||||
(vswap! *state* update :pending-to-migrate (fnil conj []) [feature file-id']))
|
|
||||||
|
|
||||||
(when (not= file-id expected-file-id)
|
(when (not= file-id expected-file-id)
|
||||||
(ex/raise :type :validation
|
(ex/raise :type :validation
|
||||||
|
@ -773,16 +766,28 @@
|
||||||
(l/dbg :hint "update media references" ::l/sync? true)
|
(l/dbg :hint "update media references" ::l/sync? true)
|
||||||
(vswap! *state* update :media into (map #(update % :id lookup-index)) media))
|
(vswap! *state* update :media into (map #(update % :id lookup-index)) media))
|
||||||
|
|
||||||
(let [file (binding [cfeat/*new* (atom #{})]
|
(let [file (-> file
|
||||||
(-> file
|
(assoc :id file-id')
|
||||||
(assoc :id file-id')
|
(process-file))
|
||||||
(assoc :features features)
|
|
||||||
(assoc :project-id project-id)
|
;; All features that are enabled and requires explicit migration are
|
||||||
(assoc :created-at timestamp)
|
;; added to the state for a posterior migration step.
|
||||||
(assoc :modified-at timestamp)
|
_ (doseq [feature (-> enabled-features
|
||||||
(dissoc :thumbnails)
|
(set/difference cfeat/no-migration-features)
|
||||||
(update :data process-fdata file-id')
|
(set/difference (:features file)))]
|
||||||
(update :features into (deref cfeat/*new*))))
|
(vswap! *state* update :pending-to-migrate (fnil conj []) [feature file-id']))
|
||||||
|
|
||||||
|
file (-> file
|
||||||
|
(assoc :project-id project-id)
|
||||||
|
(assoc :created-at timestamp)
|
||||||
|
(assoc :modified-at timestamp)
|
||||||
|
(dissoc :thumbnails)
|
||||||
|
(update :features
|
||||||
|
(fn [features]
|
||||||
|
(let [features (cfeat/check-supported-features! features)]
|
||||||
|
(-> enabled-features
|
||||||
|
(set/difference cfeat/frontend-only-features)
|
||||||
|
(set/union features))))))
|
||||||
|
|
||||||
_ (when (contains? cf/flags :file-schema-validation)
|
_ (when (contains? cf/flags :file-schema-validation)
|
||||||
(fval/validate-file-schema! file))
|
(fval/validate-file-schema! file))
|
||||||
|
@ -803,7 +808,6 @@
|
||||||
file))
|
file))
|
||||||
file)
|
file)
|
||||||
|
|
||||||
|
|
||||||
file (-> file
|
file (-> file
|
||||||
(update :features #(db/create-array conn "text" %))
|
(update :features #(db/create-array conn "text" %))
|
||||||
(update :data blob/encode))]
|
(update :data blob/encode))]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue