Skip to content

Commit

Permalink
use the renderer to generate the backup image
Browse files Browse the repository at this point in the history
  • Loading branch information
tmoerman committed May 28, 2015
1 parent ad7393a commit b744a8c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
Binary file removed resources/backup.png
Binary file not shown.
32 changes: 20 additions & 12 deletions src/sourire/handler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
(:use [ring.middleware params
keyword-params
nested-params])
(:import (java.io ByteArrayInputStream FileInputStream)))
(:import (java.io ByteArrayInputStream))
(:import com.ggasoftware.indigo.IndigoException))

(defn serve-index [_]
{:status 200
Expand All @@ -18,19 +19,26 @@
(let [params (req :params)
smi (-> (params :smi) url-decode)
opts (-> params (dissoc :smi))
i+r (init-indigo+renderer opts)

image (->> smi
(render-to-buffer i+r)
(ByteArrayInputStream.))]
{:status 200
:body image
:headers {"Content-Type" "image/png"}})
i+r (init-indigo+renderer opts)]
(try
(let [image (->> smi
(render-to-buffer i+r)
(ByteArrayInputStream.))]
{:status 200
:body image
:headers {"Content-Type" "image/png"}})
(catch IndigoException e
(error e)
(let [backup-image (->> (url-decode "%5BBa%5D%5BC%5D%5BK%5D%5BU%5D%5BP%5D")
(render-to-buffer i+r)
(ByteArrayInputStream.))]
{:status 200
:body backup-image
:headers {"Content-Type" "image/png"}}))))
(catch Exception e
(error e)
{:status 200
:body (FileInputStream. "resources/backup.png")
:headers {"Content-Type" "image/png"}})))
{:status 400
:body (str (.getMessage e))})))

(def molecule-regex #"[a-zA-Z0-9%\.\+\-\_\*\(\)]+")

Expand Down

0 comments on commit b744a8c

Please sign in to comment.