diff --git a/CHANGES.md b/CHANGES.md index 2b75de8ad..fff4250c8 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -17,6 +17,7 @@ - Fix change opacity in colorpicker cause bugged color [Taiga #4154](https://tree.taiga.io/project/penpot/issue/4154) - Fix gradient colors don't arrive in recent colors palette (https://tree.taiga.io/project/penpot/issue/4155) - Fix selected colors allow gradients in shadows [Taiga #4156](https://tree.taiga.io/project/penpot/issue/4156) +- Fix import files with unexpected format or invalid content [Taiga #4136](https://tree.taiga.io/project/penpot/issue/4136) ## 1.15.3-beta diff --git a/frontend/src/app/main/ui/dashboard/import.cljs b/frontend/src/app/main/ui/dashboard/import.cljs index 565dda8fb..bde0f44f3 100644 --- a/frontend/src/app/main/ui/dashboard/import.cljs +++ b/frontend/src/app/main/ui/dashboard/import.cljs @@ -304,7 +304,8 @@ success-files (->> @state :files (filter #(and (= (:status %) :import-finish) (empty? (:errors %)))) count) pending-analysis? (> (->> @state :files (filter #(= (:status %) :analyzing)) count) 0) pending-import? (> (->> @state :files (filter #(= (:status %) :importing)) count) 0) - files (->> (:files @state) (filterv (comp not :deleted?)))] + files (->> (:files @state) (filterv (comp not :deleted?))) + valid-files? (> (->> files (filterv (fn [x] (not= (:status x) :analyze-error))) count) 0)] (mf/use-effect (fn [] @@ -359,7 +360,7 @@ {:class "primary" :type "button" :value (tr "labels.continue") - :disabled pending-analysis? + :disabled (or pending-analysis? (not valid-files?)) :on-click handle-continue}]) (when (= :importing (:status @state)) @@ -367,5 +368,5 @@ {:class "primary" :type "button" :value (tr "labels.accept") - :disabled pending-import? + :disabled (or pending-import? (not valid-files?)) :on-click handle-accept}])]]]])) diff --git a/frontend/src/app/worker/import.cljs b/frontend/src/app/worker/import.cljs index aff53ab5b..a1538e4b4 100644 --- a/frontend/src/app/worker/import.cljs +++ b/frontend/src/app/worker/import.cljs @@ -19,6 +19,7 @@ [app.common.uuid :as uuid] [app.main.repo :as rp] [app.util.http :as http] + [app.util.i18n :as i18n :refer [tr]] [app.util.import.parser :as cip] [app.util.json :as json] [app.util.webapi :as wapi] @@ -526,7 +527,8 @@ sg (areduce u8 i ret "" (str ret (if (zero? i) "" " ") (.toString (aget u8 i) 8)))] (case sg "120 113 3 4" "application/zip" - "application/octet-stream"))) + "1 13 32 206" "application/octet-stream" + "other"))) (defmethod impl/handler :analyze-import [{:keys [files]}] @@ -560,8 +562,15 @@ :file-id file-id :files {file-id {:name (:name file)}} :status :ready} - :type "application/octet-stream"}))))) - (rx/catch #(rx/of {:uri (:uri file) :error (.-message %)})))))))) + :type "application/octet-stream"})))) + (->> st + (rx/filter (fn [data] (= "other" (:type data)))) + (rx/map (fn [_] + {:uri (:uri file) + :error (tr "dashboard.import.analyze-error")})))) + (rx/catch (fn [data] + (let [error (or (.-message data) (tr "dashboard.import.analyze-error"))] + (rx/of {:uri (:uri file) :error error})))))))))) (defmethod impl/handler :import-files [{:keys [project-id files]}]