Skip to content

Commit 658e672

Browse files
committed
fix(assets): improve handling of external and local asset URLs
1 parent 302f798 commit 658e672

1 file changed

Lines changed: 20 additions & 11 deletions

File tree

src/main/frontend/components/block.cljs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -495,10 +495,14 @@
495495
(rum/local nil ::src)
496496
[state config title href metadata full_text]
497497
(let [src (::src state)
498-
^js js-url (:link-js-url config)
499498
href (cond-> href
500-
(nil? js-url)
501-
(config/get-local-asset-absolute-path))]
499+
(common-config/local-relative-asset? href)
500+
(config/get-local-asset-absolute-path))
501+
^js js-url (or (:link-js-url config)
502+
(when (path/protocol-url? href)
503+
(try
504+
(js/URL. href)
505+
(catch :default _ nil))))]
502506
(when (nil? @src)
503507
(-> (assets-handler/<make-asset-url href js-url)
504508
(p/then (fn [url]
@@ -562,14 +566,19 @@
562566
{:on-click (fn [e]
563567
(util/stop e)
564568
(let [repo-dir (config/get-repo-dir repo)
565-
ext-url (:logseq.property.asset/external-url asset-block)
566-
local-ext-url? (and (not (string/blank? ext-url))
567-
(common-config/local-relative-asset? ext-url))
568-
file-fpath (if local-ext-url?
569-
;; Plugin-sourced asset stored under assets/storages/<plugin-id>/...
570-
(path/path-join repo-dir (string/replace ext-url #"^[./]+" ""))
571-
(path/path-join repo-dir (str "assets/" (:block/uuid asset-block) "." (name ext))))]
572-
(js/window.apis.openPath file-fpath)))}
569+
ext-url (:logseq.property.asset/external-url asset-block)
570+
remote-ext-url? (and (not (string/blank? ext-url))
571+
(path/protocol-url? ext-url)
572+
(not (common-config/local-protocol-asset? ext-url)))
573+
local-ext-url? (and (not (string/blank? ext-url))
574+
(common-config/local-relative-asset? ext-url))
575+
file-fpath (if local-ext-url?
576+
;; Plugin-sourced asset stored under assets/storages/<plugin-id>/...
577+
(path/path-join repo-dir (string/replace ext-url #"^[./]+" ""))
578+
(path/path-join repo-dir (str "assets/" (:block/uuid asset-block) "." (name ext))))]
579+
(if remote-ext-url?
580+
(js/window.apis.openExternal ext-url)
581+
(js/window.apis.openPath file-fpath))))}
573582
file-name])
574583

575584
:else

0 commit comments

Comments
 (0)