0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-15 17:21:17 -05:00

♻️ Add missing svgparse http handler.

This commit is contained in:
Andrey Antukh 2021-01-05 13:49:39 +01:00 committed by Alonso Torres
parent 33c8743215
commit f83c8d4523
3 changed files with 40 additions and 4 deletions

View file

@ -88,8 +88,9 @@
(rr/create-resource-handler {:path "/"})
(rr/create-default-handler))))
(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
[["/metrics" {:get (:handler metrics)}]
@ -107,7 +108,7 @@
[middleware/keyword-params]
[middleware/cookies]]}
;; ["/svg" {:post handlers/parse-svg}]
["/svg" {:post svgparse}]
["/oauth"
["/google" {:post (:auth-handler google-auth)}]

View file

@ -80,8 +80,13 @@
:google-auth (ig/ref :app.http.auth/google)
:gitlab-auth (ig/ref :app.http.auth/gitlab)
:ldap-auth (ig/ref :app.http.auth/ldap)
:svgparse (ig/ref :app.svgparse/handler)
:storage (ig/ref :app.storage/storage)}
;; HTTP Handler for SVG parsing
:app.svgparse/handler
{:metrics (ig/ref :app.metrics/metrics)}
:app.rpc/rpc
{:pool (ig/ref :app.db/pool)
:session (ig/ref :app.http.session/session)

View file

@ -10,9 +10,13 @@
(ns app.svgparse
(:require
[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.io :as io])
[clojure.spec.alpha :as s]
[clojure.xml :as xml]
[integrant.core :as ig])
(:import
java.io.InputStream
org.apache.commons.io.IOUtils))
@ -35,3 +39,29 @@
(with-open [istream (io/input-stream input)]
(-> (clean-svg istream)
(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)})