فهرست منبع

fix: empty path when importing roam's json

Tienson Qin 4 سال پیش
والد
کامیت
7238c4205a
2فایلهای تغییر یافته به همراه24 افزوده شده و 22 حذف شده
  1. 2 1
      src/main/frontend/handler/external.cljs
  2. 22 21
      src/main/frontend/handler/file.cljs

+ 2 - 1
src/main/frontend/handler/external.cljs

@@ -40,7 +40,8 @@
                    files)
         files (remove nil? files)]
     (repo-handler/parse-files-and-load-to-db! repo files nil)
-    (let [files (map (fn [{:file/keys [path content]}] [path content]) files)]
+    (let [files (->> (map (fn [{:file/keys [path content]}] (when path [path content])) files)
+                     (remove nil?))]
       (file-handler/alter-files repo files {:add-history? false
                                             :update-db? false
                                             :update-status? false

+ 22 - 21
src/main/frontend/handler/file.cljs

@@ -249,27 +249,28 @@
 (defn alter-files-handler!
   [repo files {:keys [finish-handler chan]} file->content]
   (let [write-file-f (fn [[path content]]
-                       (let [original-content (get file->content path)]
-                         (-> (p/let [_ (or
-                                        (util/electron?)
-                                        (nfs/check-directory-permission! repo))]
-                               (debug/set-ack-step! path :write-file)
-                               (fs/write-file! repo (config/get-repo-dir repo) path content
-                                               {:old-content original-content}))
-                             (p/catch (fn [error]
-                                        (state/pub-event! [:notification/show
-                                                           {:content (str "Failed to save the file " path ". Error: "
-                                                                          (str error))
-                                                            :status :error
-                                                            :clear? false}])
-                                        (state/pub-event! [:instrument {:type :write-file/failed
-                                                                        :payload {:path path
-                                                                                  :content-length (count content)
-                                                                                  :error-str (str error)
-                                                                                  :error error}}])
-                                        (log/error :write-file/failed {:path path
-                                                                       :content content
-                                                                       :error error}))))))
+                       (when path
+                         (let [original-content (get file->content path)]
+                          (-> (p/let [_ (or
+                                         (util/electron?)
+                                         (nfs/check-directory-permission! repo))]
+                                (debug/set-ack-step! path :write-file)
+                                (fs/write-file! repo (config/get-repo-dir repo) path content
+                                                {:old-content original-content}))
+                              (p/catch (fn [error]
+                                         (state/pub-event! [:notification/show
+                                                            {:content (str "Failed to save the file " path ". Error: "
+                                                                           (str error))
+                                                             :status :error
+                                                             :clear? false}])
+                                         (state/pub-event! [:instrument {:type :write-file/failed
+                                                                         :payload {:path path
+                                                                                   :content-length (count content)
+                                                                                   :error-str (str error)
+                                                                                   :error error}}])
+                                         (log/error :write-file/failed {:path path
+                                                                        :content content
+                                                                        :error error})))))))
         finish-handler (fn []
                          (when finish-handler
                            (finish-handler))