Ver código fonte

fix: href asset is not loaded on Electron

Junyi Du 2 anos atrás
pai
commit
77ff2515b8
2 arquivos alterados com 16 adições e 6 exclusões
  1. 5 5
      src/main/frontend/components/block.cljs
  2. 11 1
      src/main/frontend/fs.cljs

+ 5 - 5
src/main/frontend/components/block.cljs

@@ -197,10 +197,8 @@
                             asset-path (gp-config/remove-asset-protocol src)]
                         (if (string/blank? asset-path)
                           (reset! *exist? false)
-                          (-> (fs/file-exists? "" asset-path)
-                              (p/then
-                               (fn [exist?]
-                                 (reset! *exist? (boolean exist?))))))
+                          (p/let [exist? (fs/file-or-href-exists? "" asset-path)]
+                            (reset! *exist? (boolean exist?))))
                         (assoc state ::asset-path asset-path ::asset-file? true))
                       state)))
    :will-update (fn [state]
@@ -314,8 +312,10 @@
           :title   title}
          metadata)]
        [:.asset-overlay]
-       (let [image-src (string/replace src #"^assets://" "")]
+       (let [image-src (string/replace src #"^assets://" "")
+             _ (prn "image-src:" image-src)]
          [:.asset-action-bar {:aria-hidden "true"}
+          ;; the image path bar
           (when (util/electron?)
             [:button.asset-action-btn.text-left
              {:title (t (if local? :asset/show-in-folder :asset/open-in-browser))

+ 11 - 1
src/main/frontend/fs.cljs

@@ -14,7 +14,8 @@
             [promesa.core :as p]
             [frontend.db :as db]
             [clojure.string :as string]
-            [frontend.state :as state]))
+            [frontend.state :as state]
+            [logseq.graph-parser.util :as gp-util]))
 
 (defonce nfs-record (nfs/->Nfs))
 (defonce bfs-record (bfs/->Bfs))
@@ -216,6 +217,15 @@
    (fn [stat] (not (nil? stat)))
    (fn [_e] false)))
 
+(defn file-or-href-exists?
+  "It not only accept path, but also href (url encoded path)"
+  [dir href]
+  (p/let [exist? (file-exists? dir href)
+          decoded-href   (gp-util/safe-decode-uri-component href)
+          decoded-exist? (when (not= decoded-href href)
+                           (file-exists? dir decoded-href))]
+    (or exist? decoded-exist?)))
+
 (defn dir-exists?
   [dir]
   (file-exists? dir ""))