Ver código fonte

fix: WIP assets not loading

Tienson Qin 2 anos atrás
pai
commit
37d49b6ab8

+ 3 - 0
src/electron/electron/handler.cljs

@@ -795,6 +795,9 @@
 (defmethod handle :server/set-config [^js _win [_ config]]
 (defmethod handle :server/set-config [^js _win [_ config]]
   (server/set-config! config))
   (server/set-config! config))
 
 
+(defmethod handle :system/info [^js _win _]
+  {:home-dir (.homedir os)})
+
 (defn set-ipc-handler! [window]
 (defn set-ipc-handler! [window]
   (let [main-channel "main"]
   (let [main-channel "main"]
     (.handle ipcMain main-channel
     (.handle ipcMain main-channel

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

@@ -145,7 +145,6 @@
 
 
 (defn- get-file-absolute-path
 (defn- get-file-absolute-path
   [config path]
   [config path]
-  (js/console.error "TODO: buggy path fn")
   (let [path (string/replace path "file:" "")
   (let [path (string/replace path "file:" "")
         block-id (:block/uuid config)
         block-id (:block/uuid config)
         current-file (and block-id
         current-file (and block-id
@@ -232,7 +231,6 @@
         type (cond img? "image"
         type (cond img? "image"
                    audio? "audio"
                    audio? "audio"
                    :else "asset")]
                    :else "asset")]
-
     (if (not sync-enabled?)
     (if (not sync-enabled?)
       (content-fn)
       (content-fn)
       (if (and asset-file? (or loading? (nil? exist?)))
       (if (and asset-file? (or loading? (nil? exist?)))
@@ -435,11 +433,13 @@
   (let [metadata (if (string/blank? metadata)
   (let [metadata (if (string/blank? metadata)
                    nil
                    nil
                    (gp-util/safe-read-string metadata))
                    (gp-util/safe-read-string metadata))
-        title (second (first label))]
+        title (second (first label))
+        repo (state/get-current-repo)]
     (ui/catch-error
     (ui/catch-error
      [:span.warning full_text]
      [:span.warning full_text]
      (if (and (gp-config/local-asset? href)
      (if (and (gp-config/local-asset? href)
-              (config/local-file-based-graph? (state/get-current-repo)))
+              (or (config/local-file-based-graph? repo)
+                  (config/db-based-graph? repo)))
        (asset-link config title href metadata full_text)
        (asset-link config title href metadata full_text)
        (let [href (cond
        (let [href (cond
                     (util/starts-with? href "http")
                     (util/starts-with? href "http")

+ 9 - 4
src/main/frontend/config.cljs

@@ -376,8 +376,13 @@
   (str "/" (string/replace s #"^[./]*" "")))
   (str "/" (string/replace s #"^[./]*" "")))
 
 
 (defn get-local-dir
 (defn get-local-dir
-  [s]
-  (string/replace s local-db-prefix ""))
+  [repo]
+  (if (db-based-graph? repo)
+    (path/path-join (get-in @state/state [:system/info :home-dir])
+                    "logseq"
+                    "graphs"
+                    (string/replace repo db-version-prefix ""))
+    (string/replace repo local-db-prefix "")))
 
 
 ;; FIXME(andelf): this is not the reverse op of get-repo-dir, should be fixed
 ;; FIXME(andelf): this is not the reverse op of get-repo-dir, should be fixed
 (defn get-local-repo
 (defn get-local-repo
@@ -392,8 +397,8 @@
       (js/console.error "BUG: nil repo")
       (js/console.error "BUG: nil repo")
       nil)
       nil)
 
 
-    (db-based-graph? repo-url)
-    nil
+    (and (util/electron?) (db-based-graph? repo-url))
+    (get-local-dir repo-url)
 
 
     (and (util/electron?) (local-file-based-graph? repo-url))
     (and (util/electron?) (local-file-based-graph? repo-url))
     (get-local-dir repo-url)
     (get-local-dir repo-url)

+ 9 - 1
src/main/frontend/handler.cljs

@@ -45,7 +45,8 @@
             [promesa.core :as p]
             [promesa.core :as p]
             [frontend.mobile.core :as mobile]
             [frontend.mobile.core :as mobile]
             [frontend.db.react :as db-react]
             [frontend.db.react :as db-react]
-            [frontend.db.listener :as db-listener]))
+            [frontend.db.listener :as db-listener]
+            [cljs-bean.core :as bean]))
 
 
 (defn set-global-error-notification!
 (defn set-global-error-notification!
   []
   []
@@ -200,8 +201,15 @@
 
 
 (reset! db-listener/*db-listener outliner-db/after-transact-pipelines)
 (reset! db-listener/*db-listener outliner-db/after-transact-pipelines)
 
 
+(defn- get-system-info
+  []
+  (when (util/electron?)
+    (p/let [info (ipc/ipc :system/info)]
+      (state/set-state! :system/info (bean/->clj info)))))
+
 (defn start!
 (defn start!
   [render]
   [render]
+  (get-system-info)
   (set-global-error-notification!)
   (set-global-error-notification!)
   (register-components-fns!)
   (register-components-fns!)
   (user-handler/restore-tokens-from-localstorage)
   (user-handler/restore-tokens-from-localstorage)

+ 2 - 1
src/main/frontend/handler/editor.cljs

@@ -1418,7 +1418,8 @@
   [id ^js files format uploading? drop-or-paste?]
   [id ^js files format uploading? drop-or-paste?]
   (let [repo (state/get-current-repo)
   (let [repo (state/get-current-repo)
         block (state/get-edit-block)]
         block (state/get-edit-block)]
-    (when (config/local-file-based-graph? repo)
+    (when (or (config/local-file-based-graph? repo)
+              (config/db-based-graph? repo))
       (-> (save-assets! block repo (js->clj files))
       (-> (save-assets! block repo (js->clj files))
           ;; FIXME: only the first asset is handled
           ;; FIXME: only the first asset is handled
           (p/then
           (p/then

+ 1 - 0
src/main/frontend/handler/image.cljs

@@ -15,6 +15,7 @@
                      (mobile-util/native-ios?))
                      (mobile-util/native-ios?))
                  (config/local-file-based-graph? (state/get-current-repo)))
                  (config/local-file-based-graph? (state/get-current-repo)))
     (try
     (try
+      (prn "render local images")
       (let [images (array-seq (gdom/getElementsByTagName "img"))
       (let [images (array-seq (gdom/getElementsByTagName "img"))
             get-src (fn [image] (.getAttribute image "src"))
             get-src (fn [image] (.getAttribute image "src"))
             local-images (filter
             local-images (filter

+ 2 - 1
src/main/frontend/state.cljs

@@ -289,7 +289,8 @@
       :history/page-only-mode?               false
       :history/page-only-mode?               false
       ;; db tx-id -> editor cursor
       ;; db tx-id -> editor cursor
       :history/tx->editor-cursor             (atom {})
       :history/tx->editor-cursor             (atom {})
-      :ui/pagination-blocks-range            (atom {})})))
+      :ui/pagination-blocks-range            (atom {})
+      :system/info                           {}})))
 
 
 ;; Block ast state
 ;; Block ast state
 ;; ===============
 ;; ===============