Przeglądaj źródła

fix(fs): fix custom.js path calc

Andelf 2 lat temu
rodzic
commit
d7fc1d785e
2 zmienionych plików z 18 dodań i 10 usunięć
  1. 11 5
      src/main/frontend/fs.cljs
  2. 7 5
      src/main/frontend/handler/ui.cljs

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

@@ -61,6 +61,7 @@
 (defn unlink!
   "Should move the path to logseq/recycle instead of deleting it."
   [repo fpath opts]
+  ;; TODO(andelf): better handle backup here, instead of fs impl
   (protocol/unlink! (get-fs fpath) repo fpath opts))
 
 (defn rmdir!
@@ -223,11 +224,16 @@
             false))))))
 
 (defn file-exists?
-  [dir path]
-  (util/p-handle
-   (stat dir path)
-   (fn [stat] (not (nil? stat)))
-   (fn [_e] false)))
+  ([fpath]
+   (util/p-handle
+    (stat fpath)
+    (fn [stat] (not (nil? stat)))
+    (fn [_e] false)))
+  ([dir path]
+   (util/p-handle
+    (stat dir path)
+    (fn [stat] (not (nil? stat)))
+    (fn [_e] false))))
 
 (defn asset-href-exists?
   "href is from `make-asset-url`, so it's most likely a full-path"

+ 7 - 5
src/main/frontend/handler/ui.cljs

@@ -14,7 +14,8 @@
             [clojure.string :as string]
             [rum.core :as rum]
             [electron.ipc :as ipc]
-            [promesa.core :as p]))
+            [promesa.core :as p]
+            [frontend.fs2.path :as fs2-path]))
 
 (defn- get-css-var-value
   [var-name]
@@ -123,7 +124,7 @@
                     (some-> (db-model/get-custom-css)
                             (config/expand-relative-assets-path))
                     ;; (state/get-custom-css-link)
-)]
+                    )]
     (util/add-style! style)))
 (defn reset-custom-css!
   []
@@ -155,11 +156,12 @@
           (when (or (not should-ask?)
                     (ask-allow))
             (load href #(do (js/console.log "[custom js]" href) (execed))))
-          (let [dir (if (util/electron?) "" (config/get-repo-dir (state/get-current-repo)))]
-            (p/let [exists? (fs/file-exists? dir href)]
+          (let [repo-dir (config/get-repo-dir (state/get-current-repo))
+                rpath (fs2-path/relative-path repo-dir href)]
+            (p/let [exists? (fs/file-exists? repo-dir rpath)]
               (when exists?
                 (util/p-handle
-                 (fs/read-file dir href)
+                 (fs/read-file repo-dir rpath)
                  #(when-let [scripts (and % (string/trim %))]
                     (when-not (string/blank? scripts)
                       (when (or (not should-ask?) (ask-allow))