Просмотр исходного кода

refactor(fs): open-dir now returns map instead of vec

Andelf 2 лет назад
Родитель
Сommit
43f9fa33b0

+ 2 - 2
src/main/frontend/config.cljs

@@ -484,9 +484,9 @@
 
 (defn get-current-repo-assets-root
   []
-  (when-let [repo-root (and (local-db? (state/get-current-repo))
+  (when-let [repo-dir (and (local-db? (state/get-current-repo))
                             (get-repo-dir (state/get-current-repo)))]
-    (util/node-path.join repo-root "assets")))
+    (fs2-path/path-join repo-dir "assets")))
 
 (defn get-custom-js-path
   ([]

+ 3 - 4
src/main/frontend/fs.cljs

@@ -164,13 +164,12 @@
     (p/let [result (protocol/open-dir record dir ok-handler)]
       (if (or (util/electron?)
               (mobile-util/native-platform?))
-        (let [[dir & paths] result
-              _ (prn ::open-dir result)
-              dir (:path dir)
+        (let [{:keys [path files]} result
+              dir path
               _ (prn ::open-dir dir)
               files (mapv (fn [entry]
                             (assoc entry :path (fs2-path/relative-path dir (:path entry))))
-                          paths)]
+                          files)]
           (prn :got files)
           {:path dir :files files})
         result))))

+ 0 - 14
src/main/frontend/fs/node.cljs

@@ -13,20 +13,6 @@
             [promesa.core :as p]
             [frontend.fs2.path :as fs2-path]))
 
-(defn concat-path
-  [dir path]
-  (cond
-    (nil? path)
-    dir
-
-    (string/starts-with? path dir)
-    path
-
-    :else
-    (str (string/replace dir #"/$" "")
-         (when path
-           (str "/" (string/replace path #"^/" ""))))))
-
 (defn- contents-matched?
   [disk-content db-content]
   (when (and (string? disk-content) (string? db-content))

+ 2 - 1
src/main/frontend/fs/protocol.cljs

@@ -13,7 +13,8 @@
   (rename! [this repo old-path new-path])
   (copy! [this repo old-path new-path])
   (stat [this dir path])
-  (open-dir [this dir ok-handler])
+  (open-dir [this dir ok-handler]
+    "=> {:path string :files [{...}]}")
   (list-files [this dir ok-handler]
     "dir => [{:path string :content string}]")
   (watch-dir! [this dir options])

+ 3 - 3
src/main/frontend/handler/editor.cljs

@@ -1387,8 +1387,8 @@
   [repo]
   (p/let [repo-dir (config/get-repo-dir repo)
           assets-dir "assets"
-          _ (fs/mkdir-if-not-exists (str repo-dir "/" assets-dir))]
-    (prn ::ensure-assets-dir repo-dir  assets-dir)
+          _ (fs/mkdir-if-not-exists (fs2-path/path-join repo-dir assets-dir))]
+    (prn ::ensure-assets-dir repo-dir assets-dir)
     [repo-dir assets-dir]))
 
 (defn get-asset-path
@@ -1470,7 +1470,7 @@
         (assets-handler/resolve-asset-real-path-url (state/get-current-repo) path)
 
         (util/electron?)
-        (str "assets://" full-path)
+        (fs2-path/path-join "assets://" full-path)
 
         (mobile-util/native-platform?)
         (mobile-util/convert-file-src full-path)