|
156 | 156 | link |
157 | 157 | (str protocol "://" link))))) |
158 | 158 |
|
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 | | - |
195 | 159 | (rum/defcs file-based-asset-loader |
196 | 160 | < rum/reactive |
197 | 161 | (rum/local nil ::exist?) |
|
470 | 434 | ([src] (audio-cp src nil)) |
471 | 435 | ([src ext] |
472 | 436 | ;; 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)]))))) |
479 | 444 |
|
480 | 445 | (defn- open-pdf-file |
481 | 446 | [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)] |
483 | 448 | (when-let [s (or href (some-> (.-target e) (.-dataset) (.-href)))] |
484 | 449 | (let [load$ (fn [] |
485 | 450 | (p/let [href (or href |
|
516 | 481 | (nil? js-url) |
517 | 482 | (config/get-local-asset-absolute-path)) |
518 | 483 | db-based? (config/db-based-graph? repo)] |
519 | | - |
520 | 484 | (when (nil? @src) |
521 | 485 | (-> (assets-handler/<make-asset-url href js-url) |
522 | 486 | (p/then (fn [url] |
523 | 487 | (reset! src (common-util/safe-decode-uri-component url)))) |
524 | 488 | (p/catch #(js/console.log "Failed to load asset:" %)))) |
525 | 489 | (:image-placeholder config) |
526 | | - (if-not @src |
| 490 | + (if (and (:image-placeholder config) (nil? @src)) |
527 | 491 | (:image-placeholder config) |
528 | 492 | (let [ext (keyword (or (util/get-file-ext @src) |
529 | 493 | (util/get-file-ext href))) |
|
539 | 503 | rel-dir (string/replace rel-dir #"^/+" "") |
540 | 504 | asset-url (path/path-join repo-dir rel-dir basename)] |
541 | 505 | (mobile-intent/open-or-share-file asset-url))))] |
542 | | - |
543 | 506 | (cond |
544 | 507 | (or (contains? config/audio-formats ext) |
545 | 508 | (and (= ext :webm) (string/starts-with? title "Audio-"))) |
|
635 | 598 | :else |
636 | 599 | (if (assets-handler/check-alias-path? href) |
637 | 600 | (assets-handler/normalize-asset-resource-url href) |
638 | | - (get-file-absolute-path config href)))] |
| 601 | + href))] |
639 | 602 | (resizable-image config title href metadata full_text false)))))) |
640 | 603 |
|
641 | 604 | (def timestamp-to-string export-common-handler/timestamp-to-string) |
|
1075 | 1038 | {:will-mount (fn [state] |
1076 | 1039 | (let [block (last (:rum/args state)) |
1077 | 1040 | 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))) |
1079 | 1042 | 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?) |
1081 | 1044 | ;; publishing doesn't have window.pfs defined |
1082 | 1045 | true |
1083 | 1046 | (fs/file-exists? (config/get-repo-dir (state/get-current-repo)) path))] |
|
1507 | 1470 | :else |
1508 | 1471 | (if (assets-handler/check-alias-path? href) |
1509 | 1472 | (assets-handler/resolve-asset-real-path-url (state/get-current-repo) href) |
1510 | | - (get-file-absolute-path config href)))] |
| 1473 | + href))] |
1511 | 1474 | (audio-cp href)))) |
1512 | 1475 |
|
1513 | 1476 | (defn- media-link |
|
2425 | 2388 | [(hl-ref)] |
2426 | 2389 |
|
2427 | 2390 | (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))] |
2432 | 2395 | (conj |
2433 | 2396 | (map-inline config' block-ast-title) |
2434 | 2397 | (when (= block-type :whiteboard-shape) [:span.mr-1 (ui/icon "whiteboard-element" {:extension? true})]))) |
|
0 commit comments