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

pull/8914/head
Andelf 2023-03-11 14:19:48 +08:00
parent 6082663f4c
commit 43f9fa33b0
5 changed files with 10 additions and 24 deletions

View File

@ -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
([]

View File

@ -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))))

View File

@ -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))

View File

@ -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])

View File

@ -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)