mirror of
https://github.com/penpot/penpot.git
synced 2025-05-11 06:56:37 +02:00
⬆️ Move svg parsing to the frontend with Tubax
This commit is contained in:
parent
f57fb5006d
commit
7ff608ff0b
7 changed files with 25 additions and 13 deletions
|
@ -14,8 +14,8 @@
|
|||
[app.common.spec :as us]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.main.data.dashboard :as dd]
|
||||
[app.main.data.media :as di]
|
||||
[app.main.data.fonts :as df]
|
||||
[app.main.data.media :as di]
|
||||
[app.main.data.messages :as dm]
|
||||
[app.main.data.workspace.changes :as dch]
|
||||
[app.main.data.workspace.common :as dwc]
|
||||
|
@ -39,7 +39,8 @@
|
|||
[clojure.set :as set]
|
||||
[cuerdas.core :as str]
|
||||
[potok.core :as ptk]
|
||||
[promesa.core :as p]))
|
||||
[promesa.core :as p]
|
||||
[tubax.core :as tubax]))
|
||||
|
||||
(declare persist-changes)
|
||||
(declare persist-sychronous-changes)
|
||||
|
@ -344,8 +345,12 @@
|
|||
|
||||
(defn parse-svg
|
||||
[[name text]]
|
||||
(->> (rp/query! :parsed-svg {:data text})
|
||||
(rx/map #(assoc % :name name))))
|
||||
(try
|
||||
(->> (rx/of (-> (tubax/xml->clj text)
|
||||
(assoc :name name))))
|
||||
|
||||
(catch :default err
|
||||
(rx/throw {:type :svg-parser}))))
|
||||
|
||||
(defn fetch-svg [name uri]
|
||||
(->> (http/send! {:method :get :uri uri :mode :no-cors})
|
||||
|
|
|
@ -110,14 +110,6 @@
|
|||
:response-type :blob})
|
||||
(rx/mapcat handle-response)))
|
||||
|
||||
(defmethod query :parsed-svg
|
||||
[id params]
|
||||
(->> (http/send! {:method :post
|
||||
:uri (u/join base-uri "api/rpc/query/" (name id))
|
||||
:body (http/transit-data params)})
|
||||
(rx/map http/conditional-decode-transit)
|
||||
(rx/mapcat handle-response)))
|
||||
|
||||
(derive :upload-file-media-object ::multipart-upload)
|
||||
(derive :update-profile-photo ::multipart-upload)
|
||||
(derive :update-team-photo ::multipart-upload)
|
||||
|
|
|
@ -240,6 +240,15 @@
|
|||
(js/console.error explain)))
|
||||
(js/console.groupEnd "Validation Error"))
|
||||
|
||||
;; Error on parsing an SVG
|
||||
(defmethod ptk/handle-error :svg-parser
|
||||
[error]
|
||||
(ts/schedule
|
||||
(st/emitf
|
||||
(dm/show {:content "SVG is invalid or malformed"
|
||||
:type :error
|
||||
:timeout 3000}))))
|
||||
|
||||
;; This is a pure frontend error that can be caused by an active
|
||||
;; assertion (assertion that is preserved on production builds). From
|
||||
;; the user perspective this should be treated as internal error.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue