Просмотр исходного кода

fix: UI import of example graph is invalid

With #12313, we introduced relative paths which fail to create
assets and then cause invalid blocks that are unable to reference those
assets. Any user graphs that have relative paths like this will also
have their invalid blocks fixed
Gabriel Horner 5 дней назад
Родитель
Сommit
6acf799b68

+ 2 - 1
deps/graph-parser/src/logseq/graph_parser/exporter.cljs

@@ -1311,7 +1311,8 @@
                   :type "pdf"
                   ;; avoid using the real checksum since it could be the same with in-graph asset
                   :checksum "0000000000000000000000000000000000000000000000000000000000000000"
-                  :size (.-size stat)
+                  ;; gracefully create stat-less assets so that references to them are still valid
+                  :size (if stat (.-size stat) 0)
                   :external-url (or asset-link-or-name path)
                   :external-file-name asset-path}))
         (p/catch (fn [error]

+ 2 - 1
src/main/frontend/components/imports.cljs

@@ -375,7 +375,8 @@
                    :set-ui-state state/set-state!
                    :<read-file (fn <read-file [file] (.text (:file-object file)))
                    :<get-file-stat (fn <get-file-stat [path]
-                                     (when (util/electron?)
+                                     ;; Ignore relative paths as we can't get their stats
+                                     (when (and (util/electron?) (path/absolute? path))
                                        (ipc/ipc :stat path)))
                    ;; config file options
                    :default-config config/config-default-content