Skip to content

Commit

Permalink
fix(mobile): capacitor v4 readdir api
Browse files Browse the repository at this point in the history
  • Loading branch information
andelf committed Sep 19, 2022
1 parent a183533 commit 437b928
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions src/main/frontend/fs/capacitor_fs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -82,36 +82,26 @@
(p/let [d (first dirs)
files (<readdir d)
files (->> files
(remove (fn [file]
(or (string/starts-with? file ".")
(and (mobile-util/native-android?)
(or (string/includes? file "#")
(string/includes? file "%")))
(= file "bak")))))
files (->> files
(map (fn [file]
;; TODO: use uri-join
(str (string/replace d #"/+$" "")
"/"
(if (mobile-util/native-ios?)
(js/encodeURI file)
file)))))
files-with-stats (p/all (mapv <stat files))
files-dir (->> files-with-stats
(remove (fn [{:keys [name type] :as file-info}]
(or (string/starts-with? name ".")
(and (= type "directory")
(or (= name "bak")
(= name "version-files")))))))
files-dir (->> files
(filterv #(= (:type %) "directory"))
(mapv :uri))
files-result
(p/all
(->> files-with-stats
(->> files
(filter #(= (:type %) "file"))
(filter
(fn [{:keys [uri]}]
(some #(string/ends-with? uri %)
[".md" ".markdown" ".org" ".edn" ".css"])))
(mapv
(fn [{:keys [uri] :as file-result}]
(fn [{:keys [uri] :as file-info}]
(p/chain (<read-file-with-utf8 uri)
#(assoc file-result :content %))))))]
#(assoc file-info :content %))))))]
(p/recur (concat result files-result)
(concat (rest dirs) files-dir)))))]
(js->clj result :keywordize-keys true)))
Expand Down

0 comments on commit 437b928

Please sign in to comment.