소스 검색

use js/encodeURI and js/decodeURI to process path on iOS

leizhe 3 년 전
부모
커밋
ba06e3db84
2개의 변경된 파일15개의 추가작업 그리고 28개의 파일을 삭제
  1. 2 2
      src/main/frontend/config.cljs
  2. 13 26
      src/main/frontend/fs/capacitor_fs.cljs

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

@@ -384,8 +384,8 @@
       (and (mobile-util/native-ios?) (local-db? repo-url))
       (let [dir (-> (get-repo-dir repo-url)
                     (string/replace "file:///" "file:/"))]
-        (str dir relative-path))
-      
+        (js/decodeURI (str dir relative-path)))
+
       (= "/" (first relative-path))
       (subs relative-path 1)
 

+ 13 - 26
src/main/frontend/fs/capacitor_fs.cljs

@@ -88,20 +88,7 @@
                        (p/recur (concat result files-result)
                                 (concat (rest dirs) files-dir)))))
           result (js->clj result :keywordize-keys true)]
-    (if (util/native-ios?)
-      result
-      (map (fn [result] (update result :uri clean-uri)) result))))
-
-(defn- encode-path [orig-repo orig-path]
-  (let [orig-repo (config/get-repo-dir orig-repo)
-        [repo path] (map #(-> (string/replace % "file://" "")
-                              (string/replace "file:" "")
-                              (string/escape {\  "%20"}))
-                         [orig-repo orig-path])
-        path-diff (string/replace path repo "")]
-    (str orig-repo (-> path-diff
-                       futil/url-decode
-                       futil/url-encode))))
+    (map (fn [result] (update result :uri clean-uri)) result)))
 
 (defrecord Capacitorfs []
   protocol/Fs
@@ -142,28 +129,28 @@
   (delete-file! [this repo dir path {:keys [ok-handler error-handler] :as opts}]
     (let [path (cond
                  (= (util/platform) "ios")
-                 (encode-path repo path)
+                 (js/encodeURI (js/decodeURI path))
 
                  (string/starts-with? path (config/get-repo-dir repo))
                  path
-                 
+
                  :else
                  (-> (str dir "/" path)
                      (string/replace "//" "/")))]
       (p/catch
-          (p/let [result (.deleteFile Filesystem
-                                      (clj->js
-                                       {:path path}))]
-            (when ok-handler
-              (ok-handler repo path result)))
-          (fn [error]
-            (if error-handler
-              (error-handler error)
-              (log/error :delete-file-failed error))))))
+       (p/let [result (.deleteFile Filesystem
+                                   (clj->js
+                                    {:path path}))]
+         (when ok-handler
+           (ok-handler repo path result)))
+       (fn [error]
+         (if error-handler
+           (error-handler error)
+           (log/error :delete-file-failed error))))))
   (write-file! [this repo dir path content {:keys [ok-handler error-handler] :as opts}]
     (let [path (cond
                  (= (util/platform) "ios")
-                 (encode-path repo path)
+                 (js/encodeURI (js/decodeURI path))
 
                  (string/starts-with? path (config/get-repo-dir repo))
                  path