mirror of
https://github.com/penpot/penpot.git
synced 2025-04-04 19:11:20 -05:00
Merge pull request #3506 from penpot/niwinz-staging-bugfixes-7
✨ Improve error report of invalid image
This commit is contained in:
commit
695152274c
5 changed files with 22 additions and 17 deletions
|
@ -74,7 +74,7 @@
|
|||
::yrs/headers headers}))
|
||||
|
||||
(defmethod handle-exception :validation
|
||||
[err _]
|
||||
[err request]
|
||||
(let [{:keys [code] :as data} (ex-data err)]
|
||||
(cond
|
||||
(= code :spec-validation)
|
||||
|
@ -95,6 +95,11 @@
|
|||
(= code :request-body-too-large)
|
||||
{::yrs/status 413 ::yrs/body data}
|
||||
|
||||
(= code :invalid-image)
|
||||
(binding [l/*context* (request->context request)]
|
||||
(l/error :hint "unexpected error on processing image" :cause err)
|
||||
{::yrs/status 400 ::yrs/body data})
|
||||
|
||||
:else
|
||||
{::yrs/status 400 ::yrs/body data})))
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.exceptions :as ex]
|
||||
[app.common.logging :as l]
|
||||
[app.common.media :as cm]
|
||||
[app.common.schema :as sm]
|
||||
[app.common.schema.generators :as sg]
|
||||
|
@ -227,7 +226,6 @@
|
|||
|
||||
(defmethod process-error org.im4java.core.InfoException
|
||||
[error]
|
||||
(l/error :hint "unexpected error on processing image" :cause error)
|
||||
(ex/raise :type :validation
|
||||
:code :invalid-image
|
||||
:hint "invalid image"
|
||||
|
|
|
@ -171,7 +171,8 @@
|
|||
:opt-un [::id ::name]))
|
||||
|
||||
(sv/defmethod ::create-file-media-object-from-url
|
||||
{::doc/added "1.17"}
|
||||
{::doc/added "1.17"
|
||||
::doc/deprecated "1.19"}
|
||||
[{:keys [::db/pool] :as cfg} {:keys [::rpc/profile-id file-id] :as params}]
|
||||
(let [cfg (update cfg ::sto/storage media/configure-assets-storage)]
|
||||
(files/check-edition-permissions! pool profile-id file-id)
|
||||
|
|
|
@ -73,16 +73,20 @@
|
|||
(rx/map #(svg/add-svg-shapes (assoc svg-data :image-data %) position))))))
|
||||
|
||||
(defn- process-uris
|
||||
[{:keys [file-id local? name uris mtype on-image on-svg]}]
|
||||
[{:keys [file-id local? name uris mtype on-image on-svg] }]
|
||||
(letfn [(svg-url? [url]
|
||||
(or (and mtype (= mtype "image/svg+xml"))
|
||||
(str/ends-with? url ".svg")))
|
||||
|
||||
(prepare [uri]
|
||||
{:file-id file-id
|
||||
:is-local local?
|
||||
:name (or name (svg/extract-name uri))
|
||||
:url uri})
|
||||
(upload [uri]
|
||||
(->> (http/send! {:method :get :uri uri :mode :no-cors :response-type :blob})
|
||||
(rx/map :body)
|
||||
(rx/map (fn [content]
|
||||
{:file-id file-id
|
||||
:name (or name (svg/extract-name uri))
|
||||
:is-local local?
|
||||
:content content}))
|
||||
(rx/mapcat #(rp/cmd! :upload-file-media-object %))))
|
||||
|
||||
(fetch-svg [name uri]
|
||||
(->> (http/send! {:method :get :uri uri :mode :no-cors})
|
||||
|
@ -93,8 +97,7 @@
|
|||
(rx/merge
|
||||
(->> (rx/from uris)
|
||||
(rx/filter (comp not svg-url?))
|
||||
(rx/map prepare)
|
||||
(rx/mapcat #(rp/cmd! :create-file-media-object-from-url %))
|
||||
(rx/mapcat upload)
|
||||
(rx/do on-image))
|
||||
|
||||
(->> (rx/from uris)
|
||||
|
@ -142,7 +145,7 @@
|
|||
[:local? :boolean]
|
||||
[:name {:optional true} :string]
|
||||
[:data {:optional true} :any] ; FIXME
|
||||
[:uris {:optional true} [:vector :string]]
|
||||
[:uris {:optional true} [:sequential :string]]
|
||||
[:mtype {:optional true} :string]])
|
||||
|
||||
(defn- process-media-objects
|
||||
|
@ -213,8 +216,6 @@
|
|||
:on-image #(st/emit! (dwl/add-media %)))]
|
||||
(process-media-objects params)))
|
||||
|
||||
;; TODO: it is really need handle SVG here, looks like it already
|
||||
;; handled separately
|
||||
(defn upload-media-workspace
|
||||
[{:keys [position file-id] :as params}]
|
||||
(let [params (assoc params
|
||||
|
|
|
@ -451,8 +451,8 @@
|
|||
(dnd/has-type? event "text/uri-list")
|
||||
(let [data (dnd/get-data event "text/uri-list")
|
||||
lines (str/lines data)
|
||||
uris (->> lines (filter #(str/starts-with? % "http")))
|
||||
data (->> lines (filter #(str/starts-with? % "data:image/")))
|
||||
uris (filterv #(str/starts-with? % "http") lines)
|
||||
data (filterv #(str/starts-with? % "data:image/") lines)
|
||||
params {:file-id (:id file)
|
||||
:position viewport-coord}
|
||||
params (if (seq uris)
|
||||
|
|
Loading…
Add table
Reference in a new issue