fix: upload CLI assets

This commit is contained in:
rcmerci
2026-05-26 20:30:46 +08:00
parent 073bbeb90a
commit 626a0ff418
2 changed files with 17 additions and 15 deletions

View File

@@ -1320,23 +1320,21 @@
:logseq.property.asset/checksum (:asset/checksum metadata)
:block/tags #{asset-tag-id}})
blocks)))
block-uuid (get-in action* [:blocks 0 :block/uuid])
_ (when-not (uuid? block-uuid)
(throw (ex-info "created asset block missing uuid"
{:code :asset-create-failed})))
_ (copy-asset-file-to-graph! config
(:repo action)
block-uuid
(:asset/type metadata)
asset-path)
create-result (add-command/execute-add-block (assoc action* :type :add-block) config)
created-ids (vec (or (get-in create-result [:data :result]) []))
created-id (first created-ids)
_ (when-not (some? created-id)
(throw (ex-info "asset block not created"
{:code :asset-create-failed})))
created-entity (pull-entity-by-id cfg (:repo action) [:db/id :block/uuid] created-id)
block-uuid (:block/uuid created-entity)
_ (when-not (uuid? block-uuid)
(throw (ex-info "created asset block missing uuid"
{:code :asset-create-failed
:id created-id})))
_ (copy-asset-file-to-graph! config
(:repo action)
block-uuid
(:asset/type metadata)
asset-path)]
{:code :asset-create-failed})))]
{:status :ok
:data {:result [created-id]}})

View File

@@ -77,6 +77,7 @@
(deftest test-execute-upsert-asset-create-applies-metadata-and-copies-file
(async done
(let [add-actions* (atom [])
lifecycle-calls* (atom [])
copy-calls* (atom [])
action {:type :upsert-asset
:mode :create
@@ -84,16 +85,19 @@
:graph "demo-graph"
:asset-path "/tmp/logo.png"
:content "Logo"
:blocks [{:block/title "Logo"}] }]
:blocks [{:block/title "Logo"
:block/uuid (uuid "00000000-0000-0000-0000-000000000101")}] }]
(-> (p/with-redefs [cli-server/ensure-server! (fn [config _repo]
(p/resolved (assoc config :base-url "http://example")))
upsert-command/asset-file-exists? (fn [_] true)
upsert-command/asset-file-size-bytes (fn [_] 123)
upsert-command/asset-file-checksum (fn [_] "sha-256-value")
upsert-command/copy-asset-file-to-graph! (fn [_ repo block-uuid asset-type source-path]
(swap! lifecycle-calls* conj :copy)
(swap! copy-calls* conj [repo block-uuid asset-type source-path])
"/tmp/copied/logo.png")
add-command/execute-add-block (fn [add-action _]
(swap! lifecycle-calls* conj :add-block)
(swap! add-actions* conj add-action)
(p/resolved {:status :ok
:data {:result [101]}}))
@@ -127,7 +131,8 @@
(uuid "00000000-0000-0000-0000-000000000101")
"png"
"/tmp/logo.png"]]
@copy-calls*))))
@copy-calls*))
(is (= [:copy :add-block] @lifecycle-calls*))))
(p/catch (fn [e]
(is false (str "unexpected error: " e))))
(p/finally done)))))
@@ -773,4 +778,3 @@
(p/catch (fn [e]
(is false (str "unexpected error: " e))))
(p/finally done)))))