0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-24 23:49:45 -05:00

🐛 Fix internal server error when user wants to upload image in components block via '+' icon

This commit is contained in:
Alejandro Alonso 2023-11-17 12:23:19 +01:00 committed by Andrés Moya
parent bc95416592
commit 016ead108d

View file

@ -17,7 +17,6 @@
[app.common.svg.shapes-builder :as csvg.shapes-builder] [app.common.svg.shapes-builder :as csvg.shapes-builder]
[app.common.types.container :as ctn] [app.common.types.container :as ctn]
[app.common.types.shape :as cts] [app.common.types.shape :as cts]
[app.common.types.shape-tree :as ctst]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.config :as cf] [app.config :as cf]
[app.main.data.media :as dmm] [app.main.data.media :as dmm]
@ -315,9 +314,9 @@
(defn create-shapes-img (defn create-shapes-img
"Convert a media object that contains a bitmap image into shapes, "Convert a media object that contains a bitmap image into shapes,
one shape of type :rect containing an image fill and one group that contains it." one shape of type :rect containing an image fill and one group that contains it."
[pos {:keys [name width height id mtype] :as media-obj} & {:keys [wrapper-type] :or {wrapper-type :group}}] [pos {:keys [name width height id mtype] :as media-obj}]
(let [group-shape (cts/setup-shape (let [frame-shape (cts/setup-shape
{:type wrapper-type {:type :frame
:x (:x pos) :x (:x pos)
:y (:y pos) :y (:y pos)
:width width :width width
@ -339,24 +338,18 @@
:height height :height height
:mtype mtype}}] :mtype mtype}}]
:name name :name name
:frame-id uuid/zero :frame-id (:id frame-shape)
:parent-id (:id group-shape)})] :parent-id (:id frame-shape)})]
(rx/of [group-shape [img-shape]]))) (rx/of [frame-shape [img-shape]])))
(defn- add-shapes-and-component (defn- add-shapes-and-component
[it file-data page name [shape children]] [it file-data page name [shape children]]
(let [page' (reduce #(ctst/add-shape (:id %2) %2 %1 uuid/zero (:parent-id %2) nil false) (let [[component-shape component-shapes updated-shapes]
page (ctn/convert-shape-in-component shape children (:id file-data))
(cons shape children))
shape' (ctn/get-shape page' (:id shape))
[component-shape component-shapes updated-shapes]
(ctn/make-component-shape shape' (:objects page') (:id file-data) true)
changes (-> (pcb/empty-changes it) changes (-> (pcb/empty-changes it)
(pcb/with-page page') (pcb/with-page page)
(pcb/with-objects (:objects page')) (pcb/with-objects (:objects page))
(pcb/with-library-data file-data) (pcb/with-library-data file-data)
(pcb/add-objects (cons shape children)) (pcb/add-objects (cons shape children))
(pcb/add-component (:id component-shape) (pcb/add-component (:id component-shape)