From c8593b1c18ce38092f17bee102a94e2475ec1ca6 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 24 Jan 2024 16:38:01 +0100 Subject: [PATCH] :bug: Fix get name from file when importing --- backend/src/app/rpc/commands/binfile.clj | 11 ++++++++--- frontend/src/app/worker/import.cljs | 5 ++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/backend/src/app/rpc/commands/binfile.clj b/backend/src/app/rpc/commands/binfile.clj index ebebbc42f..206b8931a 100644 --- a/backend/src/app/rpc/commands/binfile.clj +++ b/backend/src/app/rpc/commands/binfile.clj @@ -728,10 +728,11 @@ (defmethod read-section :v1/files - [{:keys [::db/conn ::input ::project-id ::enabled-features ::timestamp ::overwrite?] :as system}] + [{:keys [::db/conn ::input ::project-id ::enabled-features ::timestamp ::overwrite? ::name] :as system}] - (doseq [expected-file-id (-> *state* deref :files)] + (doseq [[idx expected-file-id] (d/enumerate (-> *state* deref :files))] (let [file (read-obj! input) + media (read-obj! input) file-id (:id file) @@ -770,6 +771,8 @@ (let [file (-> file (assoc :id file-id') + (cond-> (and (= idx 0) (some? name)) + (assoc :name name)) (process-file)) ;; All features that are enabled and requires explicit migration are @@ -1105,6 +1108,7 @@ schema:import-binfile (sm/define [:map {:title "import-binfile"} + [:name :string] [:project-id ::sm/uuid] [:file ::media/upload]])) @@ -1116,12 +1120,13 @@ ::webhooks/event? true ::sse/stream? true ::sm/params schema:import-binfile} - [{:keys [::db/pool] :as cfg} {:keys [::rpc/profile-id project-id file] :as params}] + [{:keys [::db/pool] :as cfg} {:keys [::rpc/profile-id name project-id file] :as params}] (projects/check-read-permissions! pool profile-id project-id) (let [params (-> cfg (assoc ::input (:path file)) (assoc ::project-id project-id) (assoc ::profile-id profile-id) + (assoc ::name name) (assoc ::ignore-index-errors? true))] (with-meta (sse/response #(import-binfile params)) diff --git a/frontend/src/app/worker/import.cljs b/frontend/src/app/worker/import.cljs index b1db05f9d..daea0c241 100644 --- a/frontend/src/app/worker/import.cljs +++ b/frontend/src/app/worker/import.cljs @@ -728,7 +728,10 @@ :method :get}) (rx/map :body) (rx/mapcat (fn [file] - (->> (rp/cmd! ::sse/import-binfile {:file file :project-id project-id}) + (->> (rp/cmd! ::sse/import-binfile + {:name (str/replace (:name data) #".penpot$" "") + :file file + :project-id project-id}) (rx/tap (fn [event] (let [payload (sse/get-payload event) type (sse/get-type event)]