mirror of
https://github.com/penpot/penpot.git
synced 2025-05-12 07:46:39 +02:00
✨ Removed svgcleaner
This commit is contained in:
parent
c380400578
commit
ecff4c5dce
79 changed files with 8 additions and 15953 deletions
|
@ -156,13 +156,9 @@
|
|||
:client-id (:gitlab-client-id config)
|
||||
:client-secret (:gitlab-client-secret config)}
|
||||
|
||||
:app.svgparse/svgc
|
||||
{:metrics (ig/ref :app.metrics/metrics)}
|
||||
|
||||
;; HTTP Handler for SVG parsing
|
||||
:app.svgparse/handler
|
||||
{:metrics (ig/ref :app.metrics/metrics)
|
||||
:svgc (ig/ref :app.svgparse/svgc)}
|
||||
{:metrics (ig/ref :app.metrics/metrics)}
|
||||
|
||||
;; RLimit definition for password hashing
|
||||
:app.rlimits/password
|
||||
|
@ -184,8 +180,7 @@
|
|||
:metrics (ig/ref :app.metrics/metrics)
|
||||
:storage (ig/ref :app.storage/storage)
|
||||
:msgbus (ig/ref :app.msgbus/msgbus)
|
||||
:rlimits (ig/ref :app.rlimits/all)
|
||||
:svgc (ig/ref :app.svgparse/svgc)}
|
||||
:rlimits (ig/ref :app.rlimits/all)}
|
||||
|
||||
:app.notifications/handler
|
||||
{:msgbus (ig/ref :app.msgbus/msgbus)
|
||||
|
|
|
@ -92,7 +92,7 @@
|
|||
|
||||
|
||||
(defn create-file-media-object
|
||||
[{:keys [conn storage svgc] :as cfg} {:keys [file-id is-local name content] :as params}]
|
||||
[{:keys [conn storage] :as cfg} {:keys [file-id is-local name content] :as params}]
|
||||
(media/validate-media-type (:content-type content))
|
||||
(let [storage (assoc storage :conn conn)
|
||||
source-path (fs/path (:tempfile content))
|
||||
|
@ -108,7 +108,7 @@
|
|||
:path source-path})))
|
||||
|
||||
image (if (= (:mtype source-info) "image/svg+xml")
|
||||
(let [data (svgc (slurp source-path))]
|
||||
(let [data (slurp source-path)]
|
||||
(sto/put-object storage {:content (sto/content data)
|
||||
:content-type (:mtype source-info)}))
|
||||
(sto/put-object storage {:content (sto/content source-path)
|
||||
|
|
|
@ -21,74 +21,6 @@
|
|||
java.util.function.Consumer
|
||||
org.apache.commons.io.IOUtils))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; SVG Clean
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(declare clean-svg)
|
||||
(declare prepare-context-pool)
|
||||
|
||||
(defmethod ig/pre-init-spec ::svgc [_]
|
||||
(s/keys :req-un [::mtx/metrics]))
|
||||
|
||||
(defmethod ig/init-key ::svgc
|
||||
[_ {:keys [metrics] :as cfg}]
|
||||
(let [pool (prepare-context-pool cfg)
|
||||
cfg (assoc cfg :pool pool)
|
||||
handler #(clean-svg cfg %)
|
||||
handler (->> {:registry (:registry metrics)
|
||||
:type :summary
|
||||
:name "svgc_timing"
|
||||
:help "svg optimization function timing"}
|
||||
(mtx/instrument handler))]
|
||||
(with-meta handler {::pool pool})))
|
||||
|
||||
(defmethod ig/halt-key! ::svgc
|
||||
[_ f]
|
||||
(let [{:keys [::pool]} (meta f)]
|
||||
(pool/clear! pool)
|
||||
(pool/close! pool)))
|
||||
|
||||
(defn- prepare-context-pool
|
||||
[cfg]
|
||||
(pool/create
|
||||
{:min-idle (:min-idle cfg 0)
|
||||
:max-idle (:max-idle cfg 3)
|
||||
:max-total (:max-total cfg 3)
|
||||
:create
|
||||
(fn []
|
||||
(let [ctx (graal/context "js")]
|
||||
(->> (graal/source "js" (io/resource "svgclean.js"))
|
||||
(graal/eval! ctx))
|
||||
ctx))
|
||||
:destroy
|
||||
(fn [ctx]
|
||||
(graal/close! ctx))}))
|
||||
|
||||
(defn- clean-svg
|
||||
[{:keys [pool]} data]
|
||||
(with-open [ctx (pool/acquire pool)]
|
||||
(let [res (promise)
|
||||
optimize (-> (graal/get-bindings @ctx "js")
|
||||
(graal/get-member "svgc")
|
||||
(graal/get-member "optimize"))
|
||||
resultp (graal/invoke optimize data)]
|
||||
|
||||
(graal/invoke-member resultp "then"
|
||||
(reify Consumer
|
||||
(accept [_ val]
|
||||
(deliver res val))))
|
||||
|
||||
(graal/invoke-member resultp "catch"
|
||||
(reify Consumer
|
||||
(accept [_ err]
|
||||
(deliver res err))))
|
||||
|
||||
(let [result (deref res)]
|
||||
(if (instance? Throwable result)
|
||||
(throw result)
|
||||
result)))))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Handler
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
@ -96,10 +28,8 @@
|
|||
(declare handler)
|
||||
(declare process-request)
|
||||
|
||||
(s/def ::svgc fn?)
|
||||
|
||||
(defmethod ig/pre-init-spec ::handler [_]
|
||||
(s/keys :req-un [::mtx/metrics ::svgc]))
|
||||
(s/keys :req-un [::mtx/metrics]))
|
||||
|
||||
(defmethod ig/init-key ::handler
|
||||
[_ {:keys [metrics] :as cfg}]
|
||||
|
@ -117,7 +47,7 @@
|
|||
:code :unsupported-mime-type
|
||||
:mime (get headers "content-type")))
|
||||
{:status 200
|
||||
:body (process-request cfg body)})
|
||||
:body (process-request body)})
|
||||
|
||||
(defn parse
|
||||
[data]
|
||||
|
@ -129,8 +59,7 @@
|
|||
:code :invalid-svg-file))))
|
||||
|
||||
(defn process-request
|
||||
[{:keys [svgc] :as cfg} body]
|
||||
(let [data (slurp body)
|
||||
data (svgc data)]
|
||||
[body]
|
||||
(let [data (slurp body)]
|
||||
(parse data)))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue