Only allow upload a limited set of image types.

This commit is contained in:
Andrey Antukh 2016-10-12 19:21:38 +02:00
parent a0127130a6
commit 492e57d845

View file

@ -191,12 +191,16 @@
;; --- Create Image ;; --- Create Image
(def allowed-file-types #{"image/jpeg" "image/png"})
(defrecord CreateImages [coll-id files] (defrecord CreateImages [coll-id files]
rs/WatchEvent rs/WatchEvent
(-apply-watch [_ state s] (-apply-watch [_ state s]
(letfn [(image-size [file] (letfn [(image-size [file]
(->> (files/get-image-size file) (->> (files/get-image-size file)
(rx/map (partial vector file)))) (rx/map (partial vector file))))
(allowed-file? [file]
(contains? allowed-file-types (.-type file)))
(prepare [[file [width height]]] (prepare [[file [width height]]]
{:coll coll-id {:coll coll-id
:id (uuid/random) :id (uuid/random)
@ -204,6 +208,7 @@
:width width :width width
:height height})] :height height})]
(->> (rx/from-coll (jscoll->vec files)) (->> (rx/from-coll (jscoll->vec files))
(rx/filter allowed-file?)
(rx/flat-map image-size) (rx/flat-map image-size)
(rx/map prepare) (rx/map prepare)
(rx/flat-map #(rp/req :create/image %)) (rx/flat-map #(rp/req :create/image %))