Skip to content

[DB Import] External PDF highlights with Windows URIs (file://D:\) and remote URLs (https://) fail to create Asset entities (Follow-up to #923) #1140

Closed
logseq/logseq
#13162

Description

@ccyang2019

Search first

  • I searched and no similar issues were found

What Happened?

Description

Follow-up to #923.

While POSIX-style external PDF paths (file:///tmp/...) were addressed and import correctly via import-linked-file-pdf-annotations, highlights pointing to external PDFs using Windows drive URIs (e.g., file://D:\...) or remote HTTPS URLs (https://...) still fail during legacy markdown graph migration (import-file-graph-to-db).

During import:

  1. file:: and file-path:: containing Windows drive letters or remote URLs are rejected during asset extraction.
  2. No :logseq.class/Asset entity is created in DataScript/SQLite.
  3. The corresponding annotation blocks (:logseq.class/Pdf-annotation) fail to bind to a parent :logseq.property/asset.
  4. The asset entity query evaluates to nil.

Related Issues


Reproduction Test Cases

Add the following tests to deps/graph-parser/test/logseq/graph_parser/exporter_test.cljs:

(deftest-async import-windows-linked-pdf-uri-format
  (let [annotation-id #uuid "11111111-1111-1111-1111-111111111111"
        dir (fs/mkdtempSync (node-path/join (os/tmpdir) "logseq-test-"))
        graph-dir (node-path/join dir "graph")
        windows-file-uri "file://D:\\assets\\LocalDoc.pdf"]
    (doseq [[path content]
            {"logseq/config.edn" "{}"
             "pages/source.md" (str "- ![LocalDoc.pdf](" windows-file-uri ")\n")
             "pages/hls__LocalDoc.md" (str "file:: [LocalDoc.pdf](" windows-file-uri ")\n"
                                           "file-path:: " windows-file-uri "\n\n"
                                           "- Windows highlight\n"
                                           "  ls-type:: annotation\n"
                                           "  hl-page:: 1\n"
                                           "  id:: " annotation-id "\n")}]
      (let [full-path (node-path/join graph-dir path)]
        (fs/mkdirSync (node-path/dirname full-path) #js {:recursive true})
        (fs/writeFileSync full-path content)))

    (p/let [conn (db-test/create-conn)
            assets (atom [])
            _ (import-file-graph-to-db graph-dir conn {:assets assets})
            asset (db-test/find-block-by-content @conn "LocalDoc")]
      (is (some? asset)
          "Asset entity must be created for Windows path")
      (is (string/starts-with? (str (:logseq.property.asset/external-url (db-test/readable-properties asset))) "assets:///")
          "Windows drive paths must normalize to internal assets:/// schema"))))

(deftest-async import-remote-https-pdf-annotations
  (let [annotation-id #uuid "22222222-2222-2222-2222-222222222222"
        dir (fs/mkdtempSync (node-path/join (os/tmpdir) "logseq-test-"))
        graph-dir (node-path/join dir "graph")
        remote-url "https://example.com/RemoteDoc.pdf"]
    (doseq [[path content]
            {"logseq/config.edn" "{}"
             "pages/source.md" (str "- ((22222222-2222-2222-2222-222222222222))\n")
             "pages/hls__RemoteDoc.md" (str "file:: [RemoteDoc.pdf](" remote-url ")\n"
                                            "file-path:: " remote-url "\n\n"
                                            "- Remote web highlight\n"
                                            "  ls-type:: annotation\n"
                                            "  hl-page:: 2\n"
                                            "  id:: " annotation-id "\n")}]
      (let [full-path (node-path/join graph-dir path)]
        (fs/mkdirSync (node-path/dirname full-path) #js {:recursive true})
        (fs/writeFileSync full-path content)))

    (p/let [conn (db-test/create-conn)
            assets (atom [])
            _ (import-file-graph-to-db graph-dir conn {:assets assets})
            annotation (d/entity @conn [:block/uuid annotation-id])]
      (is (some? annotation)
          "Remote HTTPS PDF highlight blocks must be preserved in the DB")
      (is (= "RemoteDoc" (:logseq.property/asset (db-test/readable-properties annotation)))
          "Remote annotation must resolve to its parent Asset"))))




### Reproduce the Bug

cd deps/graph-parser
export NODE_PATH="../../node_modules"
clj -M:test -v logseq.graph-parser.exporter-test/import-windows-linked-pdf-uri-format

### Expected Behavior

Testing logseq.graph-parser.exporter-test
Importing 2 files ...

FAIL in (import-windows-linked-pdf-uri-format) (exporter_test.cljs:2508:11)
Asset entity must be created for Windows path
expected: (some? asset)
  actual: (not (some? nil))

FAIL in (import-windows-linked-pdf-uri-format) (exporter_test.cljs:2509:11)
Windows drive paths must normalize to internal assets:/// schema
expected: (string/starts-with? (str (:logseq.property.asset/external-url (db-test/readable-properties asset))) "assets:///")
  actual: (not (string/starts-with? "" "assets:///"))

Ran 1 tests containing 2 assertions.
2 failures, 0 errors.

### Screenshots

_No response_

### Files

_No response_

### Browser, Desktop or Mobile Platform Information

_No response_

### Additional Context

_No response_

### Are you willing to submit a PR? If you know how to fix the bug.

- [ ] I'm willing to submit a PR (Thank you!)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions