Skip to content

Commit 57a012b

Browse files
committed
rename external-src-to-external-url
also fixed the issue and external audio not rendered
1 parent ad10927 commit 57a012b

12 files changed

Lines changed: 73 additions & 98 deletions

File tree

deps/db/src/logseq/db/frontend/property.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@
487487
:hide? true
488488
:public? false}
489489
:queryable? true}
490-
:logseq.property.asset/external-src {:title "External URL"
490+
:logseq.property.asset/external-url {:title "External URL"
491491
:schema {:type :string
492492
:hide? false
493493
:public? true}

deps/db/src/logseq/db/frontend/schema.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
(map (juxt :major :minor)
3838
[(parse-schema-version x) (parse-schema-version y)])))
3939

40-
(def version (parse-schema-version "65.13"))
40+
(def version (parse-schema-version "65.15"))
4141

4242
(defn major-version
4343
"Return a number.

src/main/frontend/components/assets.cljs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
[frontend.config :as config]
99
[frontend.context.i18n :refer [t]]
1010
[frontend.handler.assets :as assets-handler]
11-
[frontend.handler.notification :as notification]
11+
[frontend.handler.db-based.property :as db-property-handler]
1212
[frontend.handler.editor :as editor-handler]
13+
[frontend.handler.notification :as notification]
1314
[frontend.handler.route :as route-handler]
14-
[frontend.handler.db-based.property :as db-property-handler]
1515
[frontend.state :as state]
1616
[frontend.ui :as ui]
1717
[frontend.util :as util]
@@ -226,7 +226,7 @@
226226
[:h2.font-bold.opacity-80 "Selected directories:"]
227227
(alias-directories)])]))
228228

229-
(rum/defc edit-external-src-form
229+
(rum/defc edit-external-url-form
230230
[asset-block {:keys [url title on-saved]}]
231231
(let [[saving? set-saving?] (rum/use-state false)
232232
create? (nil? asset-block)]
@@ -256,15 +256,14 @@
256256
checksum (assets-handler/get-file-checksum src)]
257257
(db-property-handler/set-block-properties!
258258
(:db/id asset-block)
259-
{:logseq.property.asset/external-src src
259+
{:logseq.property.asset/external-url src
260260
:logseq.property.asset/checksum checksum}))]))
261261
(p/then #(when on-saved (on-saved asset-block false)))
262262
(p/catch err-handle)
263-
(p/finally #(set-saving? false)))
264-
)))}
263+
(p/finally #(set-saving? false))))))}
265264
[:label [:span.block.pb-2.text-sm.opacity-60 "Asset title:"]
266265
(shui/input {:small true :default-value title :name "title"})]
267-
[:label [:span.block.pb-2.text-sm.opacity-60 "Asset src:"]
266+
[:label [:span.block.pb-2.text-sm.opacity-60 "Asset external url:"]
268267
[:span.flex.items-center.gap-2
269268
(shui/input {:small true :default-value url :name "src"})
270269
(when (util/electron?)
@@ -278,32 +277,30 @@
278277
(when (not (string/blank? file-path))
279278
(let [^js input (-> (.-target e) (.closest "form") (.querySelector "input[name='src']"))]
280279
(set! (.-value input) file-path))))))}
281-
"Select from local"))]]
280+
"Select from disk"))]]
282281
[:div.flex.justify-end.pt-3
283282
(ui/button (if create? "Create" "Save") {:disabled saving?})]]))
284283

285-
(rum/defc edit-external-src-content
284+
(rum/defc edit-external-url-content
286285
[asset-block pdf-current]
287-
[:div.edit-external-src-content
286+
[:div.edit-external-url-content
288287
(let [on-saved! (fn [asset-block update?]
289288
(when-let [uuid' (and pdf-current (:block/uuid asset-block))]
290289
(when pdf-current (state/set-current-pdf! nil))
291290
(when (not update?) (route-handler/redirect-to-page! uuid')))
292291
(shui/dialog-close!))]
293292
(if asset-block
294293
[:div.pb-2.-mt-2
295-
(let [url (:logseq.property.asset/external-src asset-block)
294+
(let [url (:logseq.property.asset/external-url asset-block)
296295
title (:block/title asset-block)]
297-
(edit-external-src-form asset-block {:url url :title title :on-saved on-saved!}))]
296+
(edit-external-url-form asset-block {:url url :title title :on-saved on-saved!}))]
298297

299298
(when-let [url (:url pdf-current)]
300299
[:div.pb-2
301300
(shui/alert
302301
{:variant "warning"}
303302
(shui/alert-description
304-
"⚠️ PDF annotations should be with internal asset(pdf) ref block to work properly."
305-
))
303+
"⚠️ PDF annotations should be with internal asset(pdf) ref block to work properly."))
306304

307305
(let [title (util/node-path.basename url)]
308-
(edit-external-src-form asset-block {:url url :title title :on-saved on-saved!}))])
309-
))])
306+
(edit-external-url-form asset-block {:url url :title title :on-saved on-saved!}))])))])

src/main/frontend/components/block.cljs

Lines changed: 17 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -156,42 +156,6 @@
156156
link
157157
(str protocol "://" link)))))
158158

159-
(defn- get-file-absolute-path
160-
[config path]
161-
(let [path (string/replace path "file:" "")
162-
block-id (:block/uuid config)
163-
current-file (and block-id
164-
(:file/path (:block/file (:block/page (db/entity [:block/uuid block-id])))))]
165-
(when current-file
166-
(let [parts (string/split current-file #"/")
167-
parts-2 (string/split path #"/")
168-
current-dir (util/string-join-path (drop-last 1 parts))]
169-
(cond
170-
(if util/win32? (utils/win32 path) (util/starts-with? path "/"))
171-
path
172-
173-
(and (not (util/starts-with? path ".."))
174-
(not (util/starts-with? path ".")))
175-
(str current-dir "/" path)
176-
177-
:else
178-
(let [parts (loop [acc []
179-
parts (reverse parts)
180-
col (reverse parts-2)]
181-
(if (empty? col)
182-
acc
183-
(let [[part parts] (case (first col)
184-
".."
185-
[(first parts) (rest parts)]
186-
"."
187-
["" parts]
188-
[(first col) (rest parts)])]
189-
(recur (conj acc part)
190-
parts
191-
(rest col)))))
192-
parts (remove #(string/blank? %) parts)]
193-
(util/string-join-path (reverse parts))))))))
194-
195159
(rum/defcs file-based-asset-loader
196160
< rum/reactive
197161
(rum/local nil ::exist?)
@@ -470,16 +434,17 @@
470434
([src] (audio-cp src nil))
471435
([src ext]
472436
;; Change protocol to allow media fragment uris to play
473-
(let [src (string/replace-first src common-config/asset-protocol "file://")
474-
opts {:controls true
475-
:on-touch-start #(util/stop %)}]
476-
(case ext
477-
:m4a [:audio opts [:source {:src src :type "audio/mp4"}]]
478-
[:audio (assoc opts :src src)]))))
437+
(when src
438+
(let [src (string/replace-first src common-config/asset-protocol "file://")
439+
opts {:controls true
440+
:on-touch-start #(util/stop %)}]
441+
(case ext
442+
:m4a [:audio opts [:source {:src src :type "audio/mp4"}]]
443+
[:audio (assoc opts :src src)])))))
479444

480445
(defn- open-pdf-file
481446
[e block href]
482-
(let [href (or (:logseq.property.asset/external-src block) href)]
447+
(let [href (or (:logseq.property.asset/external-url block) href)]
483448
(when-let [s (or href (some-> (.-target e) (.-dataset) (.-href)))]
484449
(let [load$ (fn []
485450
(p/let [href (or href
@@ -516,14 +481,13 @@
516481
(nil? js-url)
517482
(config/get-local-asset-absolute-path))
518483
db-based? (config/db-based-graph? repo)]
519-
520484
(when (nil? @src)
521485
(-> (assets-handler/<make-asset-url href js-url)
522486
(p/then (fn [url]
523487
(reset! src (common-util/safe-decode-uri-component url))))
524488
(p/catch #(js/console.log "Failed to load asset:" %))))
525489
(:image-placeholder config)
526-
(if-not @src
490+
(if (and (:image-placeholder config) (nil? @src))
527491
(:image-placeholder config)
528492
(let [ext (keyword (or (util/get-file-ext @src)
529493
(util/get-file-ext href)))
@@ -539,7 +503,6 @@
539503
rel-dir (string/replace rel-dir #"^/+" "")
540504
asset-url (path/path-join repo-dir rel-dir basename)]
541505
(mobile-intent/open-or-share-file asset-url))))]
542-
543506
(cond
544507
(or (contains? config/audio-formats ext)
545508
(and (= ext :webm) (string/starts-with? title "Audio-")))
@@ -635,7 +598,7 @@
635598
:else
636599
(if (assets-handler/check-alias-path? href)
637600
(assets-handler/normalize-asset-resource-url href)
638-
(get-file-absolute-path config href)))]
601+
href))]
639602
(resizable-image config title href metadata full_text false))))))
640603

641604
(def timestamp-to-string export-common-handler/timestamp-to-string)
@@ -1075,9 +1038,9 @@
10751038
{:will-mount (fn [state]
10761039
(let [block (last (:rum/args state))
10771040
asset-type (:logseq.property.asset/type block)
1078-
external-src? (not (string/blank? (:logseq.property.asset/external-src block)))
1041+
external-url? (not (string/blank? (:logseq.property.asset/external-url block)))
10791042
path (path/path-join common-config/local-assets-dir (str (:block/uuid block) "." asset-type))]
1080-
(p/let [result (if (or external-src? config/publishing?)
1043+
(p/let [result (if (or external-url? config/publishing?)
10811044
;; publishing doesn't have window.pfs defined
10821045
true
10831046
(fs/file-exists? (config/get-repo-dir (state/get-current-repo)) path))]
@@ -1507,7 +1470,7 @@
15071470
:else
15081471
(if (assets-handler/check-alias-path? href)
15091472
(assets-handler/resolve-asset-real-path-url (state/get-current-repo) href)
1510-
(get-file-absolute-path config href)))]
1473+
href))]
15111474
(audio-cp href))))
15121475

15131476
(defn- media-link
@@ -2425,10 +2388,10 @@
24252388
[(hl-ref)]
24262389

24272390
(let [config' (cond-> config
2428-
(and (:page-ref? config)
2429-
(= 1 (count block-ast-title))
2430-
(= "Link" (ffirst block-ast-title)))
2431-
(assoc :node-ref-link-only? true))]
2391+
(and (:page-ref? config)
2392+
(= 1 (count block-ast-title))
2393+
(= "Link" (ffirst block-ast-title)))
2394+
(assoc :node-ref-link-only? true))]
24322395
(conj
24332396
(map-inline config' block-ast-title)
24342397
(when (= block-type :whiteboard-shape) [:span.mr-1 (ui/icon "whiteboard-element" {:extension? true})])))

src/main/frontend/components/content.cljs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,12 +284,6 @@
284284
(when-not db?
285285
(block-template block-id))
286286

287-
(when (and db? (= "pdf" (:logseq.property.asset/type block)))
288-
(shui/dropdown-menu-item
289-
{:key "Edit asset source url"
290-
:on-click #(state/pub-event! [:asset/dialog-edit-external-src block])}
291-
"Edit Asset source url"))
292-
293287
(cond
294288
(srs/card-block? block)
295289
(shui/dropdown-menu-item

src/main/frontend/components/property/value.cljs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@
4141
[promesa.core :as p]
4242
[rum.core :as rum]))
4343

44+
;; TODO: support :string editing
45+
(defonce string-value-on-click
46+
{:logseq.property.asset/external-url
47+
(fn [block]
48+
(state/pub-event! [:asset/dialog-edit-external-url block]))})
49+
4450
(defn- entity-map?
4551
[m]
4652
(and (map? m) (:db/id m)))
@@ -1240,7 +1246,14 @@
12401246
(property-block-value value block property page-cp opts)
12411247
12421248
:else
1243-
(inline-text {} :markdown (macro-util/expand-value-if-macro (str value) (state/get-macros))))]))
1249+
(let [content (inline-text {} :markdown (macro-util/expand-value-if-macro (str value) (state/get-macros)))]
1250+
(if (contains? (set (keys string-value-on-click))
1251+
(:db/ident property))
1252+
[:div.w-full {:on-click (fn []
1253+
(let [f (get string-value-on-click (:db/ident property))]
1254+
(f block)))}
1255+
content]
1256+
content)))]))
12441257
12451258
(rum/defc single-number-input
12461259
[block property value-block table-view?]

src/main/frontend/extensions/pdf/assets.cljs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@
160160
(let [ref-asset-id (:image content)
161161
image? (not (nil? ref-asset-id))
162162
text (if image? (.toLocaleString (js/Date.))
163-
(:text content))
163+
(:text content))
164164
colors (:property/closed-values (db/entity :logseq.property.pdf/hl-color))
165165
color-id (some (fn [color] (when (= (:block/title color) (:color properties))
166166
(:db/id color))) colors)]
@@ -361,8 +361,8 @@
361361
[block]
362362
(let [hl-value (:logseq.property.pdf/hl-value block)
363363
asset (:logseq.property/asset block)
364-
external-src (:logseq.property.asset/external-src asset)
365-
file-path (or external-src (str "../assets/" (:block/uuid asset) ".pdf"))]
364+
external-url (:logseq.property.asset/external-url asset)
365+
file-path (or external-url (str "../assets/" (:block/uuid asset) ".pdf"))]
366366
(if asset
367367
(->
368368
(p/let [href (assets-handler/<make-asset-url file-path)]

src/main/frontend/extensions/pdf/core.cljs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@
175175
;; colors
176176
(let [pdf-current (state/get-current-pdf)]
177177
(if (and (config/db-based-graph?) (not (:block pdf-current)))
178-
(state/pub-event! [:asset/dialog-edit-external-src nil pdf-current])
178+
(state/pub-event! [:asset/dialog-edit-external-url nil pdf-current])
179179
(let [properties {:color action}]
180180
(if-not id
181181
;; add highlight
@@ -401,10 +401,10 @@
401401
(for [hl page-hls]
402402
(let [vw-hl (update-in hl [:position] #(pdf-utils/scaled-to-vw-pos viewer %))]
403403
(rum/with-key
404-
(if (get-in hl [:content :image])
405-
(pdf-highlight-area-region viewer vw-hl hl ops)
406-
(pdf-highlights-text-region viewer vw-hl hl ops))
407-
(:id hl))))])
404+
(if (get-in hl [:content :image])
405+
(pdf-highlight-area-region viewer vw-hl hl ops)
406+
(pdf-highlights-text-region viewer vw-hl hl ops))
407+
(:id hl))))])
408408

409409
(rum/defc ^:large-vars/cleanup-todo pdf-highlight-area-selection
410410
[^js viewer {:keys [show-ctx-menu!]}]

src/main/frontend/extensions/pdf/toolbar.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@
601601
:on-click (fn []
602602
(if asset-block
603603
(pdf-assets/goto-annotations-page! (:pdf/current @state/state))
604-
(state/pub-event! [:asset/dialog-edit-external-src nil pdf-current])))}
604+
(state/pub-event! [:asset/dialog-edit-external-url nil pdf-current])))}
605605
(svg/annotations 16)]
606606

607607
;; system window

src/main/frontend/handler/editor.cljs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,16 +1534,16 @@
15341534
(fs/write-plain-text-file! repo dir file-rpath content nil)))))
15351535

15361536
(defn- new-asset-block
1537-
[repo ^js file {:keys [repo-dir asset-dir-rpath external-src]}]
1537+
[repo ^js file {:keys [repo-dir asset-dir-rpath external-url]}]
15381538
;; WARN file name maybe fully qualified path when paste file
15391539
(p/let [[file title] (if (map? file) [(:src file) (:title file)] [file nil])
1540-
[file external-src] (if (string? file) [nil file] [file external-src])
1541-
file-name (node-path/basename (or (some-> file (.-name)) (str external-src)))
1540+
[file external-url] (if (string? file) [nil file] [file external-url])
1541+
file-name (node-path/basename (or (some-> file (.-name)) (str external-url)))
15421542
file-name-without-ext* (db-asset/asset-name->title file-name)
15431543
file-name-without-ext (if (= file-name-without-ext* "image")
15441544
(date/get-date-time-string-2)
15451545
file-name-without-ext*)
1546-
checksum (some-> (or file external-src) (assets-handler/get-file-checksum))
1546+
checksum (some-> (or file external-url) (assets-handler/get-file-checksum))
15471547
size (or (some-> file (.-size)) 0)
15481548
existing-asset (some->> checksum (db-async/<get-asset-with-checksum repo))]
15491549
(if existing-asset
@@ -1574,7 +1574,7 @@
15741574
{:block/title (or title file-name-without-ext)
15751575
:block/uuid block-id
15761576
:logseq.property.asset/type ext
1577-
:logseq.property.asset/external-src external-src
1577+
:logseq.property.asset/external-url external-url
15781578
:logseq.property.asset/size size
15791579
:logseq.property.asset/checksum checksum
15801580
:block/tags #{(:db/id asset)}})))))

0 commit comments

Comments
 (0)