diff --git a/backend/src/app/media.clj b/backend/src/app/media.clj index 13219f23a4..42a4c9f48f 100644 --- a/backend/src/app/media.clj +++ b/backend/src/app/media.clj @@ -185,8 +185,9 @@ ;; --- Utility functions (defn validate-media-type - [media-type] - (when-not (cm/valid-media-types media-type) - (ex/raise :type :validation - :code :media-type-not-allowed - :hint "Seems like you are uploading an invalid media object"))) + ([mtype] (validate-media-type mtype cm/valid-media-types)) + ([mtype allowed] + (when-not (contains? allowed mtype) + (ex/raise :type :validation + :code :media-type-not-allowed + :hint "Seems like you are uploading an invalid media object")))) diff --git a/backend/src/app/rpc/mutations/profile.clj b/backend/src/app/rpc/mutations/profile.clj index 055a225cf4..18916fc198 100644 --- a/backend/src/app/rpc/mutations/profile.clj +++ b/backend/src/app/rpc/mutations/profile.clj @@ -382,8 +382,8 @@ (sv/defmethod ::update-profile-photo [{:keys [pool storage] :as cfg} {:keys [profile-id file] :as params}] - (media/validate-media-type (:content-type file)) (db/with-atomic [conn pool] + (media/validate-media-type (:content-type file) #{"image/jpeg" "image/png" "image/webp"}) (let [profile (db/get-by-id conn :profile profile-id) _ (media/run cfg {:cmd :info :input {:path (:tempfile file) :mtype (:content-type file)}}) diff --git a/backend/src/app/rpc/mutations/teams.clj b/backend/src/app/rpc/mutations/teams.clj index b7a8eaaa25..fd8f75576d 100644 --- a/backend/src/app/rpc/mutations/teams.clj +++ b/backend/src/app/rpc/mutations/teams.clj @@ -252,9 +252,10 @@ (sv/defmethod ::update-team-photo [{:keys [pool storage] :as cfg} {:keys [profile-id file team-id] :as params}] - (media/validate-media-type (:content-type file)) (db/with-atomic [conn pool] (teams/check-edition-permissions! conn profile-id team-id) + (media/validate-media-type (:content-type file) #{"image/jpeg" "image/png" "image/webp"}) + (let [team (teams/retrieve-team conn profile-id team-id) _ (media/run cfg {:cmd :info :input {:path (:tempfile file) :mtype (:content-type file)}})