mirror of
https://github.com/penpot/penpot.git
synced 2025-05-18 02:06:10 +02:00
✨ Add better file feature handling on file retrieval
This commit is contained in:
parent
90f5b4b631
commit
09d28d8583
3 changed files with 75 additions and 48 deletions
|
@ -189,6 +189,8 @@
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(defn check-features-compatibility!
|
(defn check-features-compatibility!
|
||||||
|
"Function responsible to check if provided features are supported by
|
||||||
|
the current backend"
|
||||||
[features]
|
[features]
|
||||||
(let [not-supported (set/difference features supported-features)]
|
(let [not-supported (set/difference features supported-features)]
|
||||||
(when (seq not-supported)
|
(when (seq not-supported)
|
||||||
|
@ -248,28 +250,10 @@
|
||||||
(into #{} (comp (filter pmap/pointer-map?)
|
(into #{} (comp (filter pmap/pointer-map?)
|
||||||
(map pmap/get-id)))))
|
(map pmap/get-id)))))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;; FIXME: file locking
|
||||||
;; QUERY COMMANDS
|
(defn- process-components-v2-feature
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
"A special case handling of the components/v2 feature."
|
||||||
|
[conn {:keys [id features data] :as file}]
|
||||||
(defn handle-file-features!
|
|
||||||
[conn {:keys [id features data] :as file} client-features]
|
|
||||||
|
|
||||||
(when (and (contains? features "components/v2")
|
|
||||||
(not (contains? client-features "components/v2")))
|
|
||||||
(ex/raise :type :restriction
|
|
||||||
:code :feature-mismatch
|
|
||||||
:feature "components/v2"
|
|
||||||
:hint "file has 'components/v2' feature enabled but frontend didn't specifies it"))
|
|
||||||
|
|
||||||
;; NOTE: this operation is needed because the components migration
|
|
||||||
;; generates a new page with random id which is returned to the
|
|
||||||
;; client; without persisting the migration this can cause that two
|
|
||||||
;; simultaneous clients can have a different view of the file data
|
|
||||||
;; and end persisting two pages with main components and breaking
|
|
||||||
;; the whole file
|
|
||||||
(let [file (if (and (contains? client-features "components/v2")
|
|
||||||
(not (contains? features "components/v2")))
|
|
||||||
(binding [pmap/*tracked* (atom {})]
|
(binding [pmap/*tracked* (atom {})]
|
||||||
(let [data (ctf/migrate-to-components-v2 data)
|
(let [data (ctf/migrate-to-components-v2 data)
|
||||||
features (conj features "components/v2")
|
features (conj features "components/v2")
|
||||||
|
@ -281,13 +265,43 @@
|
||||||
(persist-pointers! conn id)
|
(persist-pointers! conn id)
|
||||||
(-> file
|
(-> file
|
||||||
(assoc :features features)
|
(assoc :features features)
|
||||||
(assoc :data data))))
|
(assoc :data data)))))
|
||||||
file)]
|
|
||||||
|
(defn handle-file-features!
|
||||||
|
[conn {:keys [features] :as file} client-features]
|
||||||
|
|
||||||
|
;; Check features compatibility between the currently supported features on
|
||||||
|
;; the current backend instance and the file retrieved from the database
|
||||||
|
(check-features-compatibility! features)
|
||||||
|
|
||||||
(cond-> file
|
(cond-> file
|
||||||
|
(and (contains? features "components/v2")
|
||||||
|
(not (contains? client-features "components/v2")))
|
||||||
|
(as-> file (ex/raise :type :restriction
|
||||||
|
:code :feature-mismatch
|
||||||
|
:feature "components/v2"
|
||||||
|
:hint "file has 'components/v2' feature enabled but frontend didn't specifies it"
|
||||||
|
:file-id (:id file)))
|
||||||
|
|
||||||
|
;; This operation is needed because the components migration generates a new
|
||||||
|
;; page with random id which is returned to the client; without persisting
|
||||||
|
;; the migration this can cause that two simultaneous clients can have a
|
||||||
|
;; different view of the file data and end persisting two pages with main
|
||||||
|
;; components and breaking the whole file."
|
||||||
|
(and (contains? client-features "components/v2")
|
||||||
|
(not (contains? features "components/v2")))
|
||||||
|
(as-> file (process-components-v2-feature conn file))
|
||||||
|
|
||||||
|
;; This operation is needed for backward comapatibility with frontends that
|
||||||
|
;; does not support pointer-map resolution mechanism; this just resolves the
|
||||||
|
;; pointers on backend and return a complete file.
|
||||||
(and (contains? features "storage/pointer-map")
|
(and (contains? features "storage/pointer-map")
|
||||||
(not (contains? client-features "storage/pointer-map")))
|
(not (contains? client-features "storage/pointer-map")))
|
||||||
(process-pointers deref))))
|
(process-pointers deref)))
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;; QUERY COMMANDS
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
;; --- COMMAND QUERY: get-file (by id)
|
;; --- COMMAND QUERY: get-file (by id)
|
||||||
|
|
||||||
|
|
|
@ -323,3 +323,13 @@
|
||||||
:rfn (fn [^Reader rdr]
|
:rfn (fn [^Reader rdr]
|
||||||
(let [^List x (read-object! rdr)]
|
(let [^List x (read-object! rdr)]
|
||||||
(Matrix. (.get x 0) (.get x 1) (.get x 2) (.get x 3) (.get x 4) (.get x 5))))})
|
(Matrix. (.get x 0) (.get x 1) (.get x 2) (.get x 3) (.get x 4) (.get x 5))))})
|
||||||
|
|
||||||
|
|
||||||
|
;; Backward compatibility for 1.19 with v1.20;
|
||||||
|
|
||||||
|
(add-handlers!
|
||||||
|
{:name "penpot/geom/rect"
|
||||||
|
:rfn read-map-like}
|
||||||
|
{:name "penpot/shape"
|
||||||
|
:rfn read-map-like})
|
||||||
|
|
||||||
|
|
|
@ -100,6 +100,9 @@
|
||||||
(nil? shape)
|
(nil? shape)
|
||||||
nil
|
nil
|
||||||
|
|
||||||
|
(= uuid/zero (:id shape))
|
||||||
|
nil
|
||||||
|
|
||||||
(and (not (ctk/in-component-copy? shape)) (not allow-main?))
|
(and (not (ctk/in-component-copy? shape)) (not allow-main?))
|
||||||
nil
|
nil
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue