1
0
Эх сурвалжийг харах

fix(fs): asset path on windows

Andelf 2 жил өмнө
parent
commit
94b27014dd

+ 3 - 0
deps/common/src/logseq/common/path.cljs

@@ -199,6 +199,9 @@
           path (gp-util/safe-decode-uri-component (.-pathname url))
           path (if (string/starts-with? path "///")
                  (subs path 2)
+                 path)
+          path (if (re-find #"(?i)^/[a-zA-Z]:" path) ;; Win path fix
+                 (subs path 1)
                  path)]
       path)
     original-url))

+ 1 - 1
deps/graph-parser/src/logseq/graph_parser/config.cljs

@@ -32,7 +32,7 @@
   [s]
   (if (local-protocol-asset? s)
     (-> s
-        (string/replace-first asset-protocol "")
+        (string/replace-first asset-protocol "file://")
         (string/replace-first capacitor-protocol-with-prefix "file://")
         (string/replace-first capacitor-x-protocol-with-prefix "file://"))
     s))

+ 3 - 2
src/main/frontend/components/block.cljs

@@ -202,7 +202,8 @@
                       (let [*exist? (::exist? state)
                             ;; special handling for asset:// protcol
                             ;; Capacitor uses a special URL for assets loading
-                            asset-path (gp-config/remove-asset-protocol src)]
+                            asset-path (gp-config/remove-asset-protocol src)
+                            asset-path (fs/asset-path-normalize asset-path)]
                         (if (string/blank? asset-path)
                           (reset! *exist? false)
                           ;; FIXME(andelf): possible bug here
@@ -313,7 +314,7 @@
           :title   title}
          metadata)]
        [:.asset-overlay]
-       (let [image-src (string/replace src #"^assets://" "")]
+       (let [image-src (fs/asset-path-normalize src)]
          [:.asset-action-bar {:aria-hidden "true"}
           ;; the image path bar
           (when (util/electron?)

+ 12 - 0
src/main/frontend/fs.cljs

@@ -246,6 +246,18 @@
     (prn ::href-exists href exist?)
     exist?))
 
+(defn asset-path-normalize
+  [path]
+  (cond
+    (util/electron?)
+    (path/url-to-path path)
+
+    (mobile-util/native-platform?)
+    path
+
+    :else
+    path))
+
 (defn dir-exists?
   [dir]
   (file-exists? dir ""))