Upload SVG as shapes

This commit is contained in:
alonso.torres 2021-01-07 12:26:55 +01:00
parent 5b79928590
commit 802f19453d
28 changed files with 839 additions and 244 deletions

View file

@ -125,7 +125,7 @@
(ex/raise :type :validation
:code :media-type-mismatch
:hint (str "Seems like you are uploading a file whose content does not match the extension."
"Expected: " mtype "Got: " mtype')))
"Expected: " mtype ". Got: " mtype')))
{:width (.getImageWidth instance)
:height (.getImageHeight instance)
:mtype mtype'})))

View file

@ -84,7 +84,7 @@
:thumbnail-id (:id thumb)
:width (:width source-info)
:height (:height source-info)
:mtype (:mtype source-info)})))
:mtype source-mtype})))
;; --- Create File Media Object (from URL)

View file

@ -11,6 +11,7 @@
(:require
[app.common.exceptions :as ex]
[app.common.spec :as us]
[cuerdas.core :as str]
[app.metrics :as mtx]
[clojure.java.io :as io]
[clojure.java.shell :as shell]
@ -25,10 +26,25 @@
[^String data]
(IOUtils/toInputStream data "UTF-8"))
(defn- stream->string
[input]
(with-open [istream (io/input-stream input)]
(-> (IOUtils/toString input "UTF-8"))))
(defn- clean-svg
[^InputStream input]
(let [result (shell/sh "svgcleaner" "-c" "-" :in input :out-enc :bytes)]
(when (not= 0 (:exit result))
(let [result (shell/sh
;; "svgcleaner" "--allow-bigger-file" "-c" "-"
"svgo"
"--enable=prefixIds,removeDimensions,removeXMLNS,removeScriptElement"
"--disable=removeViewBox,moveElemsAttrsToGroup"
"-i" "-" "-o" "-"
:in input :out-enc :bytes)
err-str (:err result)]
(when (or (not= 0 (:exit result))
;; svgcleaner returns 0 with some errors, we need to check
(and (not= err-str "") (not (nil? err-str)) (str/starts-with? err-str "Error")))
(ex/raise :type :validation
:code :unable-to-optimize
:hint (:err result)))