diff --git a/backend/src/app/media.clj b/backend/src/app/media.clj index 5df82a266b..710275a542 100644 --- a/backend/src/app/media.clj +++ b/backend/src/app/media.clj @@ -55,7 +55,7 @@ (sm/check-fn schema:input)) (defn validate-media-type! - ([upload] (validate-media-type! upload cm/valid-image-types)) + ([upload] (validate-media-type! upload cm/image-types)) ([upload allowed] (when-not (contains? allowed (:mtype upload)) (ex/raise :type :validation diff --git a/common/src/app/common/media.cljc b/common/src/app/common/media.cljc index b6f2311fb5..4cdf8488ce 100644 --- a/common/src/app/common/media.cljc +++ b/common/src/app/common/media.cljc @@ -9,11 +9,18 @@ (:require [cuerdas.core :as str])) -;; We have added ".ttf" as string to solve a problem with chrome input selector -(def valid-font-types #{"font/ttf" ".ttf" "font/woff", "application/font-woff" "woff" "font/otf" ".otf" "font/opentype"}) -(def valid-image-types #{"image/jpeg", "image/png", "image/webp", "image/gif", "image/svg+xml"}) -(def str-image-types (str/join "," valid-image-types)) -(def str-font-types (str/join "," valid-font-types)) +(def font-types + #{"font/ttf" + "font/woff" + "font/otf" + "font/opentype"}) + +(def image-types + #{"image/jpeg" + "image/png" + "image/webp" + "image/gif" + "image/svg+xml"}) (defn format->extension [format] diff --git a/frontend/src/app/main/data/media.cljs b/frontend/src/app/main/data/media.cljs index 904623505c..e2506ff67e 100644 --- a/frontend/src/app/main/data/media.cljs +++ b/frontend/src/app/main/data/media.cljs @@ -15,6 +15,9 @@ [cljs.spec.alpha :as s] [cuerdas.core :as str])) +(def accept-image-types + (str/join "," cm/image-types)) + ;; --- Predicates (defn file? @@ -38,7 +41,7 @@ (defn validate-file "Check that a file obtained with the file javascript API is valid." [file] - (when-not (contains? cm/valid-image-types (.-type file)) + (when-not (contains? cm/image-types (.-type file)) (ex/raise :type :validation :code :media-type-not-allowed :hint (str/ffmt "media type % is not supported" (.-type file)))) diff --git a/frontend/src/app/main/ui/dashboard/fonts.cljs b/frontend/src/app/main/ui/dashboard/fonts.cljs index c03aa5bebf..00f547511a 100644 --- a/frontend/src/app/main/ui/dashboard/fonts.cljs +++ b/frontend/src/app/main/ui/dashboard/fonts.cljs @@ -29,6 +29,11 @@ [okulary.core :as l] [rumext.v2 :as mf])) +(def ^:private accept-font-types + (str (str/join "," font-types) + ;; A workaround to solve a problem with chrome input selector + ",.ttf,application/font-woff,woff,.otf")) + (defn- use-page-title [team section] (mf/with-effect [team] @@ -180,7 +185,7 @@ :tab-index "0"} [:span (tr "labels.add-custom-font")] [:& file-uploader {:input-id "font-upload" - :accept cm/str-font-types + :accept accept-font-types :multi true :ref input-ref :on-selected on-selected}]] diff --git a/frontend/src/app/main/ui/workspace/sidebar/assets/components.cljs b/frontend/src/app/main/ui/workspace/sidebar/assets/components.cljs index c53002203f..966afb05f2 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/assets/components.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/assets/components.cljs @@ -525,7 +525,7 @@ :aria-label (tr "workspace.assets.components.add-component") :on-click add-component :icon "add"} - [:& file-uploader {:accept cm/str-image-types + [:& file-uploader {:accept dwm/accept-image-types :multi true :ref input-ref :on-selected on-file-selected}]])] diff --git a/frontend/src/app/main/ui/workspace/top_toolbar.cljs b/frontend/src/app/main/ui/workspace/top_toolbar.cljs index 0532008ffe..1438f33072 100644 --- a/frontend/src/app/main/ui/workspace/top_toolbar.cljs +++ b/frontend/src/app/main/ui/workspace/top_toolbar.cljs @@ -64,7 +64,7 @@ i/img [:& file-uploader {:input-id "image-upload" - :accept cm/str-image-types + :accept dwm/accept-image-types :multi true :ref ref :on-selected on-selected}]]]))