mirror of
https://github.com/penpot/penpot.git
synced 2025-08-07 14:38:33 +02:00
✨ Simplify media mime types structs
This commit is contained in:
parent
d9d2cc7b4e
commit
8f774a3611
6 changed files with 25 additions and 10 deletions
|
@ -55,7 +55,7 @@
|
||||||
(sm/check-fn schema:input))
|
(sm/check-fn schema:input))
|
||||||
|
|
||||||
(defn validate-media-type!
|
(defn validate-media-type!
|
||||||
([upload] (validate-media-type! upload cm/valid-image-types))
|
([upload] (validate-media-type! upload cm/image-types))
|
||||||
([upload allowed]
|
([upload allowed]
|
||||||
(when-not (contains? allowed (:mtype upload))
|
(when-not (contains? allowed (:mtype upload))
|
||||||
(ex/raise :type :validation
|
(ex/raise :type :validation
|
||||||
|
|
|
@ -9,11 +9,18 @@
|
||||||
(:require
|
(:require
|
||||||
[cuerdas.core :as str]))
|
[cuerdas.core :as str]))
|
||||||
|
|
||||||
;; We have added ".ttf" as string to solve a problem with chrome input selector
|
(def font-types
|
||||||
(def valid-font-types #{"font/ttf" ".ttf" "font/woff", "application/font-woff" "woff" "font/otf" ".otf" "font/opentype"})
|
#{"font/ttf"
|
||||||
(def valid-image-types #{"image/jpeg", "image/png", "image/webp", "image/gif", "image/svg+xml"})
|
"font/woff"
|
||||||
(def str-image-types (str/join "," valid-image-types))
|
"font/otf"
|
||||||
(def str-font-types (str/join "," valid-font-types))
|
"font/opentype"})
|
||||||
|
|
||||||
|
(def image-types
|
||||||
|
#{"image/jpeg"
|
||||||
|
"image/png"
|
||||||
|
"image/webp"
|
||||||
|
"image/gif"
|
||||||
|
"image/svg+xml"})
|
||||||
|
|
||||||
(defn format->extension
|
(defn format->extension
|
||||||
[format]
|
[format]
|
||||||
|
|
|
@ -15,6 +15,9 @@
|
||||||
[cljs.spec.alpha :as s]
|
[cljs.spec.alpha :as s]
|
||||||
[cuerdas.core :as str]))
|
[cuerdas.core :as str]))
|
||||||
|
|
||||||
|
(def accept-image-types
|
||||||
|
(str/join "," cm/image-types))
|
||||||
|
|
||||||
;; --- Predicates
|
;; --- Predicates
|
||||||
|
|
||||||
(defn file?
|
(defn file?
|
||||||
|
@ -38,7 +41,7 @@
|
||||||
(defn validate-file
|
(defn validate-file
|
||||||
"Check that a file obtained with the file javascript API is valid."
|
"Check that a file obtained with the file javascript API is valid."
|
||||||
[file]
|
[file]
|
||||||
(when-not (contains? cm/valid-image-types (.-type file))
|
(when-not (contains? cm/image-types (.-type file))
|
||||||
(ex/raise :type :validation
|
(ex/raise :type :validation
|
||||||
:code :media-type-not-allowed
|
:code :media-type-not-allowed
|
||||||
:hint (str/ffmt "media type % is not supported" (.-type file))))
|
:hint (str/ffmt "media type % is not supported" (.-type file))))
|
||||||
|
|
|
@ -29,6 +29,11 @@
|
||||||
[okulary.core :as l]
|
[okulary.core :as l]
|
||||||
[rumext.v2 :as mf]))
|
[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
|
(defn- use-page-title
|
||||||
[team section]
|
[team section]
|
||||||
(mf/with-effect [team]
|
(mf/with-effect [team]
|
||||||
|
@ -180,7 +185,7 @@
|
||||||
:tab-index "0"}
|
:tab-index "0"}
|
||||||
[:span (tr "labels.add-custom-font")]
|
[:span (tr "labels.add-custom-font")]
|
||||||
[:& file-uploader {:input-id "font-upload"
|
[:& file-uploader {:input-id "font-upload"
|
||||||
:accept cm/str-font-types
|
:accept accept-font-types
|
||||||
:multi true
|
:multi true
|
||||||
:ref input-ref
|
:ref input-ref
|
||||||
:on-selected on-selected}]]
|
:on-selected on-selected}]]
|
||||||
|
|
|
@ -525,7 +525,7 @@
|
||||||
:aria-label (tr "workspace.assets.components.add-component")
|
:aria-label (tr "workspace.assets.components.add-component")
|
||||||
:on-click add-component
|
:on-click add-component
|
||||||
:icon "add"}
|
:icon "add"}
|
||||||
[:& file-uploader {:accept cm/str-image-types
|
[:& file-uploader {:accept dwm/accept-image-types
|
||||||
:multi true
|
:multi true
|
||||||
:ref input-ref
|
:ref input-ref
|
||||||
:on-selected on-file-selected}]])]
|
:on-selected on-file-selected}]])]
|
||||||
|
|
|
@ -64,7 +64,7 @@
|
||||||
i/img
|
i/img
|
||||||
[:& file-uploader
|
[:& file-uploader
|
||||||
{:input-id "image-upload"
|
{:input-id "image-upload"
|
||||||
:accept cm/str-image-types
|
:accept dwm/accept-image-types
|
||||||
:multi true
|
:multi true
|
||||||
:ref ref
|
:ref ref
|
||||||
:on-selected on-selected}]]]))
|
:on-selected on-selected}]]]))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue