diff --git a/backend/src/uxbox/images.clj b/backend/src/uxbox/images.clj index 9af8636de..6f7127a18 100644 --- a/backend/src/uxbox/images.clj +++ b/backend/src/uxbox/images.clj @@ -10,6 +10,7 @@ [clojure.java.io :as io] [clojure.spec.alpha :as s] [datoteka.core :as fs] + [uxbox.common.exceptions :as ex] [uxbox.common.data :as d] [uxbox.common.spec :as us] [uxbox.util.storage :as ust] @@ -108,8 +109,12 @@ (ByteArrayInputStream. thumbnail-data))))) (defn info - [path] + [content-type path] (let [instance (Info. (str path))] + (when-not (= content-type (.getProperty instance "Mime type")) + (ex/raise :type :validation + :code :image-type-mismatch + :hint "Seems like you are uploading a file whose content does not match the extension.")) {:width (.getImageWidth instance) :height (.getImageHeight instance)})) diff --git a/backend/src/uxbox/services/mutations/files.clj b/backend/src/uxbox/services/mutations/files.clj index c1723078a..2b5d6a33c 100644 --- a/backend/src/uxbox/services/mutations/files.clj +++ b/backend/src/uxbox/services/mutations/files.clj @@ -165,7 +165,7 @@ :code :image-type-not-allowed :hint "Seems like you are uploading an invalid image.")) - (let [image-opts (images/info (:tempfile content)) + (let [image-opts (images/info (:content-type content) (:tempfile content)) image-path (imgs/persist-image-on-fs content) thumb-opts imgs/thumbnail-options thumb-path (imgs/persist-image-thumbnail-on-fs thumb-opts image-path)] diff --git a/backend/src/uxbox/services/mutations/images.clj b/backend/src/uxbox/services/mutations/images.clj index 69ee47e52..d5ad3bcc4 100644 --- a/backend/src/uxbox/services/mutations/images.clj +++ b/backend/src/uxbox/services/mutations/images.clj @@ -146,7 +146,8 @@ (ex/raise :type :validation :code :image-type-not-allowed :hint "Seems like you are uploading an invalid image.")) - (let [image-opts (images/info (:tempfile content)) + + (let [image-opts (images/info (:content-type content) (:tempfile content)) image-path (persist-image-on-fs content) thumb-opts thumbnail-options thumb-path (persist-image-thumbnail-on-fs thumb-opts image-path)] diff --git a/backend/src/uxbox/services/mutations/profile.clj b/backend/src/uxbox/services/mutations/profile.clj index 17c8ebc76..9f262a858 100644 --- a/backend/src/uxbox/services/mutations/profile.clj +++ b/backend/src/uxbox/services/mutations/profile.clj @@ -291,7 +291,8 @@ (ex/raise :type :validation :code :image-type-not-allowed :hint "Seems like you are uploading an invalid image.")) - (let [thumb-opts {:width 256 + (let [image-opts (images/info (:content-type file) (:tempfile file)) + thumb-opts {:width 256 :height 256 :quality 75 :format "webp"} diff --git a/frontend/src/uxbox/main/data/messages.cljs b/frontend/src/uxbox/main/data/messages.cljs index e92623e1f..5e6fbbf3b 100644 --- a/frontend/src/uxbox/main/data/messages.cljs +++ b/frontend/src/uxbox/main/data/messages.cljs @@ -47,9 +47,10 @@ ptk/WatchEvent (watch [_ state stream] - (->> (rx/of #(dissoc % :message)) - (rx/delay +animation-timeout+))))) - + (let [stoper (rx/filter (ptk/type? ::show) stream)] + (->> (rx/of #(dissoc % :message)) + (rx/delay +animation-timeout+) + (rx/take-until stoper)))))) (defn error ([content] (error content {})) diff --git a/frontend/src/uxbox/main/ui/messages.cljs b/frontend/src/uxbox/main/ui/messages.cljs index a5b293a3b..f3da0b676 100644 --- a/frontend/src/uxbox/main/ui/messages.cljs +++ b/frontend/src/uxbox/main/ui/messages.cljs @@ -25,7 +25,8 @@ :warning i/msg-warning :error i/msg-error :success i/msg-success - :info i/msg-info)) + :info i/msg-info + i/msg-error)) (mf/defc notification-item [{:keys [type status on-close quick? content] :as props}] diff --git a/frontend/src/uxbox/util/webapi.cljs b/frontend/src/uxbox/util/webapi.cljs index 137a18d76..473c64bca 100644 --- a/frontend/src/uxbox/util/webapi.cljs +++ b/frontend/src/uxbox/util/webapi.cljs @@ -75,12 +75,12 @@ [data] (assert (string? data) "`data` should be string") (let [cboard (unchecked-get js/navigator "clipboard")] - (.writeText cboard data))) + (.writeText ^js cboard data))) (defn- read-from-clipboard [] (let [cboard (unchecked-get js/navigator "clipboard")] - (rx/from (.readText cboard)))) + (rx/from (.readText ^js cboard)))) (defn- read-image-from-clipboard [] @@ -91,7 +91,7 @@ (if img-type (rx/from (.getType item img-type)) (rx/empty))))] - (->> (rx/from (.read cboard)) ;; Get a stream of item lists + (->> (rx/from (.read ^js cboard)) ;; Get a stream of item lists (rx/mapcat identity) ;; Convert each item into an emission (rx/switch-map read-item))))