mirror of
https://github.com/penpot/penpot.git
synced 2025-05-16 06:06:13 +02:00
♻️ Add missing svgparse http handler.
This commit is contained in:
parent
33c8743215
commit
f83c8d4523
3 changed files with 40 additions and 4 deletions
|
@ -88,8 +88,9 @@
|
||||||
(rr/create-resource-handler {:path "/"})
|
(rr/create-resource-handler {:path "/"})
|
||||||
(rr/create-default-handler))))
|
(rr/create-default-handler))))
|
||||||
|
|
||||||
|
|
||||||
(defn- create-router
|
(defn- create-router
|
||||||
[{:keys [session rpc google-auth gitlab-auth metrics ldap-auth storage] :as cfg}]
|
[{:keys [session rpc google-auth gitlab-auth metrics ldap-auth storage svgparse] :as cfg}]
|
||||||
(rr/router
|
(rr/router
|
||||||
[["/metrics" {:get (:handler metrics)}]
|
[["/metrics" {:get (:handler metrics)}]
|
||||||
|
|
||||||
|
@ -107,7 +108,7 @@
|
||||||
[middleware/keyword-params]
|
[middleware/keyword-params]
|
||||||
[middleware/cookies]]}
|
[middleware/cookies]]}
|
||||||
|
|
||||||
;; ["/svg" {:post handlers/parse-svg}]
|
["/svg" {:post svgparse}]
|
||||||
|
|
||||||
["/oauth"
|
["/oauth"
|
||||||
["/google" {:post (:auth-handler google-auth)}]
|
["/google" {:post (:auth-handler google-auth)}]
|
||||||
|
|
|
@ -80,8 +80,13 @@
|
||||||
:google-auth (ig/ref :app.http.auth/google)
|
:google-auth (ig/ref :app.http.auth/google)
|
||||||
:gitlab-auth (ig/ref :app.http.auth/gitlab)
|
:gitlab-auth (ig/ref :app.http.auth/gitlab)
|
||||||
:ldap-auth (ig/ref :app.http.auth/ldap)
|
:ldap-auth (ig/ref :app.http.auth/ldap)
|
||||||
|
:svgparse (ig/ref :app.svgparse/handler)
|
||||||
:storage (ig/ref :app.storage/storage)}
|
:storage (ig/ref :app.storage/storage)}
|
||||||
|
|
||||||
|
;; HTTP Handler for SVG parsing
|
||||||
|
:app.svgparse/handler
|
||||||
|
{:metrics (ig/ref :app.metrics/metrics)}
|
||||||
|
|
||||||
:app.rpc/rpc
|
:app.rpc/rpc
|
||||||
{:pool (ig/ref :app.db/pool)
|
{:pool (ig/ref :app.db/pool)
|
||||||
:session (ig/ref :app.http.session/session)
|
:session (ig/ref :app.http.session/session)
|
||||||
|
|
|
@ -10,9 +10,13 @@
|
||||||
(ns app.svgparse
|
(ns app.svgparse
|
||||||
(:require
|
(:require
|
||||||
[app.common.exceptions :as ex]
|
[app.common.exceptions :as ex]
|
||||||
[clojure.xml :as xml]
|
[app.common.spec :as us]
|
||||||
|
[app.metrics :as mtx]
|
||||||
|
[clojure.java.io :as io]
|
||||||
[clojure.java.shell :as shell]
|
[clojure.java.shell :as shell]
|
||||||
[clojure.java.io :as io])
|
[clojure.spec.alpha :as s]
|
||||||
|
[clojure.xml :as xml]
|
||||||
|
[integrant.core :as ig])
|
||||||
(:import
|
(:import
|
||||||
java.io.InputStream
|
java.io.InputStream
|
||||||
org.apache.commons.io.IOUtils))
|
org.apache.commons.io.IOUtils))
|
||||||
|
@ -35,3 +39,29 @@
|
||||||
(with-open [istream (io/input-stream input)]
|
(with-open [istream (io/input-stream input)]
|
||||||
(-> (clean-svg istream)
|
(-> (clean-svg istream)
|
||||||
(xml/parse))))
|
(xml/parse))))
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;; Handler
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
(declare handler)
|
||||||
|
|
||||||
|
(defmethod ig/pre-init-spec ::handler [_]
|
||||||
|
(s/keys :req-un [::mtx/metrics]))
|
||||||
|
|
||||||
|
(defmethod ig/init-key ::handler
|
||||||
|
[_ {:keys [metrics] :as cfg}]
|
||||||
|
(->> {:registry (:registry metrics)
|
||||||
|
:type :summary
|
||||||
|
:name "http_handler_svgparse_timing"
|
||||||
|
:help "svg parse timings"}
|
||||||
|
(mtx/instrument handler)))
|
||||||
|
|
||||||
|
(defn- handler
|
||||||
|
[{:keys [headers body] :as request}]
|
||||||
|
(when (not= "image/svg+xml" (get headers "content-type"))
|
||||||
|
(ex/raise :type :validation
|
||||||
|
:code :unsupported-mime-type
|
||||||
|
:mime (get headers "content-type")))
|
||||||
|
{:status 200
|
||||||
|
:body (parse body)})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue