mirror of
https://github.com/logseq/logseq.git
synced 2026-04-25 06:35:02 +00:00
Reconstructed to meet bb requirements
This commit is contained in:
@@ -1256,16 +1256,9 @@
|
||||
(concat txs
|
||||
(build-pdf-annotations-tx* asset-edn-map (get @pdf-annotation-pages asset-md-name) parent-asset image-asset-name-to-uuids opts))))))
|
||||
|
||||
(defn- <handle-assets-in-block
|
||||
"If a block contains assets, creates them as #Asset nodes in the Asset page and references them in the block."
|
||||
[block {:keys [asset-links zotero-imported-files zotero-linked-files]} {:keys [assets ignored-assets pdf-annotation-pages]} {:keys [notify-user <get-file-stat user-config] :as opts}]
|
||||
(let [linked-files (when (seq zotero-linked-files) (atom zotero-linked-files))
|
||||
linked-base-dir (when linked-files
|
||||
(get-in user-config [:zotero/settings-v2 "default" :zotero-linked-attachment-base-directory]))]
|
||||
(if (seq asset-links)
|
||||
(p/let [asset-maps* (p/all (map
|
||||
(fn [asset-link]
|
||||
(p/let [link-map (second asset-link)
|
||||
(defn- resolve-asset-data
|
||||
[asset-link user-config linked-files linked-base-dir zotero-imported-files]
|
||||
(let [link-map (second asset-link)
|
||||
path* (-> link-map :url second)
|
||||
zotero-path-data (when (map? path*)
|
||||
(get-zotero-local-pdf-path user-config link-map))
|
||||
@@ -1295,40 +1288,37 @@
|
||||
(and zotero-asset? asset-name) (string/replace path #"[^/]+$" asset-name)
|
||||
:else path)
|
||||
asset-link-or-name (or link asset-name)
|
||||
asset-data* (when asset-link-or-name (get @assets asset-link-or-name))
|
||||
external-props (when zotero-asset?
|
||||
(if linked-path
|
||||
{:zotero-linked-file linked-relative}
|
||||
{:zotero-imported-file (string/join ns-util/namespace-char [(last (string/split link #"/")) asset-name])}))
|
||||
_ (when (and asset-link-or-name
|
||||
(not asset-data*)
|
||||
{:zotero-imported-file (string/join ns-util/namespace-char [(last (string/split link #"/")) asset-name])}))]
|
||||
{:asset-link-or-name asset-link-or-name
|
||||
:asset-name asset-name
|
||||
:external-props external-props
|
||||
:path path
|
||||
:zotero-asset? zotero-asset?}))
|
||||
|
||||
(defn- ensure-asset-data!
|
||||
[assets asset-link-or-name path asset-name external-props <get-file-stat]
|
||||
(when (and asset-link-or-name
|
||||
(not (get @assets asset-link-or-name))
|
||||
(string/ends-with? path ".pdf")
|
||||
(fn? <get-file-stat)) ; external pdf
|
||||
(->
|
||||
(p/let [^js stat (<get-file-stat path)]
|
||||
(fn? <get-file-stat))
|
||||
(-> (p/let [^js stat (<get-file-stat path)]
|
||||
(swap! assets assoc asset-link-or-name
|
||||
{:asset-id (d/squuid)
|
||||
:type "pdf"
|
||||
;; avoid using the real checksum since it could be the same with in-graph asset
|
||||
:checksum "0000000000000000000000000000000000000000000000000000000000000000"
|
||||
:size (.-size stat)
|
||||
:external-url (or link path)
|
||||
:external-url (or asset-link-or-name path)
|
||||
:external-file-name asset-name
|
||||
:external-props external-props}))
|
||||
(p/catch (fn [error]
|
||||
(js/console.error error)))))
|
||||
asset-data (when asset-link-or-name (get @assets asset-link-or-name))]
|
||||
(if asset-data
|
||||
(cond
|
||||
(not (get-asset-block-id assets asset-link-or-name))
|
||||
(notify-user {:msg (str "Skipped creating asset " (pr-str asset-link-or-name) " because it has no asset id")
|
||||
:level :error})
|
||||
(js/console.error error))))))
|
||||
|
||||
;; If asset tx is already built, no need to do it again
|
||||
(:asset-created? asset-data)
|
||||
{:asset-name-uuid [asset-link-or-name (:asset-id asset-data)]}
|
||||
|
||||
:else
|
||||
(defn- build-asset-tx
|
||||
[asset-data asset-name asset-link-or-name asset-link pdf-annotation-pages opts assets zotero-asset?]
|
||||
(let [new-asset (merge (build-new-asset asset-data)
|
||||
{:block/title (db-asset/asset-name->title (node-path/basename asset-name))
|
||||
:block/uuid (get-asset-block-id assets asset-link-or-name)}
|
||||
@@ -1346,6 +1336,32 @@
|
||||
(swap! assets assoc-in [asset-link-or-name :asset-created?] true)
|
||||
{:asset-name-uuid [asset-link-or-name (:block/uuid new-asset)]
|
||||
:asset-tx asset-tx}))
|
||||
|
||||
(defn- <handle-assets-in-block
|
||||
"If a block contains assets, creates them as #Asset nodes in the Asset page and references them in the block."
|
||||
[block {:keys [asset-links zotero-imported-files zotero-linked-files]} {:keys [assets ignored-assets pdf-annotation-pages]} {:keys [notify-user <get-file-stat user-config] :as opts}]
|
||||
(let [linked-files (when (seq zotero-linked-files) (atom zotero-linked-files))
|
||||
linked-base-dir (when linked-files
|
||||
(get-in user-config [:zotero/settings-v2 "default" :zotero-linked-attachment-base-directory]))]
|
||||
(if (seq asset-links)
|
||||
(p/let [asset-maps* (p/all (map
|
||||
(fn [asset-link]
|
||||
(p/let [{:keys [asset-link-or-name asset-name external-props path zotero-asset?]}
|
||||
(resolve-asset-data asset-link user-config linked-files linked-base-dir zotero-imported-files)
|
||||
_ (ensure-asset-data! assets asset-link-or-name path asset-name external-props <get-file-stat)
|
||||
asset-data (when asset-link-or-name (get @assets asset-link-or-name))]
|
||||
(if asset-data
|
||||
(cond
|
||||
(not (get-asset-block-id assets asset-link-or-name))
|
||||
(notify-user {:msg (str "Skipped creating asset " (pr-str asset-link-or-name) " because it has no asset id")
|
||||
:level :error})
|
||||
|
||||
;; If asset tx is already built, no need to do it again
|
||||
(:asset-created? asset-data)
|
||||
{:asset-name-uuid [asset-link-or-name (:asset-id asset-data)]}
|
||||
|
||||
:else
|
||||
(build-asset-tx asset-data asset-name asset-link-or-name asset-link pdf-annotation-pages opts assets zotero-asset?))
|
||||
(when-not zotero-asset? ; no need to report warning for zotero managed pdf files
|
||||
(swap! ignored-assets conj
|
||||
{:reason "No asset data found for this asset path"
|
||||
|
||||
Reference in New Issue
Block a user