From a9778555c14922fe16e4fe62e1d3526354caa1d6 Mon Sep 17 00:00:00 2001 From: "A. S." <12621257+VictorVow@users.noreply.github.com> Date: Fri, 15 May 2026 10:13:58 +0100 Subject: [PATCH] fix(asset): handle external-url paths and plugin binary writes (#12656) --- src/main/frontend/components/block.cljs | 16 ++++++++++++++-- src/main/frontend/handler/events/ui.cljs | 5 ++++- src/main/logseq/api/db_based.cljs | 4 ++-- src/main/logseq/api/plugin.cljs | 21 ++++++++++++++++++++- 4 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/main/frontend/components/block.cljs b/src/main/frontend/components/block.cljs index 1679f6932d..3b81af0ea4 100644 --- a/src/main/frontend/components/block.cljs +++ b/src/main/frontend/components/block.cljs @@ -562,7 +562,13 @@ {:on-click (fn [e] (util/stop e) (let [repo-dir (config/get-repo-dir repo) - file-fpath (path/path-join repo-dir (str "assets/" (:block/uuid asset-block) "." (name ext)))] + ext-url (:logseq.property.asset/external-url asset-block) + local-ext-url? (and (not (string/blank? ext-url)) + (common-config/local-relative-asset? ext-url)) + file-fpath (if local-ext-url? + ;; Plugin-sourced asset stored under assets/storages//... + (path/path-join repo-dir (string/replace ext-url #"^[./]+" "")) + (path/path-join repo-dir (str "assets/" (:block/uuid asset-block) "." (name ext))))] (js/window.apis.openPath file-fpath)))} file-name]) @@ -1113,13 +1119,19 @@ img-placeholder (when image? [:div.img-placeholder.asset-container {:style img-metadata}]) + ;; When external-url is set, use it as the render path so + ;; plugin-sandboxed assets (./assets/storages//...) + ;; resolve correctly; uint8 — anything it accepts as binary, we route + through writeFileBytes instead of write-plain-text-file!." + [content] + (or (instance? js/ArrayBuffer content) + (instance? js/Uint8Array content) + (and (exists? js/ArrayBuffer) (.isView js/ArrayBuffer content)) + (and (object? content) + (= "Buffer" (aget content "type")) + (array? (aget content "data"))))) + (defn- write_rootdir_file [file content sub-root root-dir] (p/let [repo "" @@ -98,7 +111,13 @@ user-path-root (util/node-path.dirname user-path) exist? (fs/file-exists? user-path-root "") _ (when-not exist? (fs/mkdir-recur! user-path-root)) - _ (fs/write-plain-text-file! repo nil user-path content {:skip-compare? true})] + ;; Binary content (ArrayBuffer/Uint8Array/...) can't survive + ;; transit serialization through ipc/ipc inside write-plain-text-file!, + ;; so on Electron we bypass to window.apis.writeFileBytes — same path + ;; the native fs/write-asset-file! uses for the same reason. + _ (if (and (binary-content? content) (util/electron?)) + (js/window.apis.writeFileBytes user-path (assets-handler/->uint8 content)) + (fs/write-plain-text-file! repo nil user-path content {:skip-compare? true}))] user-path)) (defn write_dotdir_file