fix: WIP assets not loading

pull/10016/head
Tienson Qin 2023-06-27 19:07:57 +08:00
parent f6080b3657
commit 37d49b6ab8
7 changed files with 30 additions and 11 deletions

View File

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

View File

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

View File

@ -376,8 +376,13 @@
(str "/" (string/replace s #"^[./]*" "")))
(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
(defn get-local-repo
@ -392,8 +397,8 @@
(js/console.error "BUG: nil repo")
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))
(get-local-dir repo-url)

View File

@ -45,7 +45,8 @@
[promesa.core :as p]
[frontend.mobile.core :as mobile]
[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!
[]
@ -200,8 +201,15 @@
(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!
[render]
(get-system-info)
(set-global-error-notification!)
(register-components-fns!)
(user-handler/restore-tokens-from-localstorage)

View File

@ -1418,7 +1418,8 @@
[id ^js files format uploading? drop-or-paste?]
(let [repo (state/get-current-repo)
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))
;; FIXME: only the first asset is handled
(p/then

View File

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

View File

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