فهرست منبع

fix(electron): assets:// url handling

Andelf 2 سال پیش
والد
کامیت
6082663f4c

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

@@ -30,6 +30,7 @@
 
 (defn remove-asset-protocol
   [s]
+  (js/console.error "BUG: remove-asset-protocol")
   (if (local-protocol-asset? s)
     (-> s
         (string/replace-first asset-protocol "")

+ 2 - 2
src/electron/electron/core.cljs

@@ -68,8 +68,8 @@
    (fn [^js request callback]
      (let [url (.-url request)
            url (decode-protected-assets-schema-path url)
-           path (js/decodeURI url)
-           path (string/replace path "assets://" "")]
+           path (string/replace url "assets://" "")
+           path (js/decodeURIComponent path)]
        (callback #js {:path path}))))
 
   (.registerFileProtocol

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

@@ -81,7 +81,8 @@
             [reitit.frontend.easy :as rfe]
             [rum.core :as rum]
             [shadow.loader :as loader]
-            [datascript.impl.entity :as e]))
+            [datascript.impl.entity :as e]
+            [frontend.fs2.path :as fs2-path]))
 
 (defn safe-read-string
   ([s]
@@ -199,7 +200,7 @@
                     (if (and (gp-config/local-protocol-asset? src)
                              (file-sync/current-graph-sync-on?))
                       (let [*exist? (::exist? state)
-                            asset-path (gp-config/remove-asset-protocol src)]
+                            asset-path (fs2-path/url-to-path src)]
                         (if (string/blank? asset-path)
                           (reset! *exist? false)
                           ;; FIXME(andelf): possible bug here

+ 1 - 0
src/main/frontend/config.cljs

@@ -474,6 +474,7 @@
 (defn expand-relative-assets-path
   ;; ../assets/xxx -> {assets|file}://{current-graph-root-path}/xxx
   [source]
+  (js/console.error "BUG: assets:// url handling")
   (when-let [protocol (and (string? source)
                            (not (string/blank? source))
                            (if (util/electron?) "assets" "file"))]

+ 0 - 2
src/main/frontend/fs/node.cljs

@@ -69,7 +69,6 @@
               ext (string/lower-case (util/get-file-ext rpath))
               db-content (or old-content (db/get-file repo rpath) "")
               contents-matched? (contents-matched? disk-content db-content)]
-        (prn ::disk disk-content ::db db-content ::new content)
         (cond
           (and
            (not= stat :not-found)         ; file on the disk was deleted
@@ -77,7 +76,6 @@
            (not (contains? #{"excalidraw" "edn" "css"} ext))
            (not (string/includes? rpath "/.recycle/")))
           (do
-            (prn ::?????)
             (state/pub-event! [:file/not-matched-from-disk rpath disk-content content]))
 
           :else

+ 8 - 3
src/main/frontend/fs2/path.cljs

@@ -203,9 +203,13 @@
 (defn url-to-path
   "Extract path part of a URL. decoded"
   [original-url]
-  (let [^js url (js/URL. original-url)
-        path (gp-util/safe-decode-uri-component (.-pathname url))]
-    path))
+  (if (is-file-url original-url)
+    ;; NOTE: URL type is not consistent across all protocols
+    ;; Check file:// and assets://, pathname behavior is different
+    (let [^js url (js/URL. (string/replace original-url "assets://" "file://"))
+          path (gp-util/safe-decode-uri-component (.-pathname url))]
+      path)
+    original-url))
 
 
 (defn relative-path
@@ -213,6 +217,7 @@
    Works for both path and URL."
   [base-path sub-path]
   (prn :rel-path base-path sub-path)
+  ;; (js/console.trace)
   (let [base-path (path-normalize base-path)
         sub-path (path-normalize sub-path)
         is-url? (is-file-url base-path)]