windingwind / zotero-better-notes

Everything about note management. All in Zotero.
GNU Affero General Public License v3.0
5.17k stars 183 forks source link

[Bug] Better Notes Sync Error: Error: getFilePathAsync() can only be called on attachment items #1053

Closed saccohuo closed 1 month ago

saccohuo commented 1 month ago

Is there an existing issue for this?

Are you using the latest Zotero and the latest plugin?

Environment

Describe the bug

When export note file, plugin throw error: Better Notes Sync Error: Error: getFilePathAsync() can only be called on attachment items

Debug Output

Submit…
Clear
1721838131778   addons.xpi  WARN    Checking C:\Program Files\Zotero\distribution\extensions for addons

1721838132688   addons.webextension.Knowledge4Zotero@windingwind.com    WARN    Loading extension 'Knowledge4Zotero@windingwind.com': Reading manifest: Warning processing version: version must be a version string consisting of at most 4 integers of at most 9 digits without leading zeros, and separated with dots

[JavaScript Error: "Error: Failed to load resource://services-settings/remote-settings.sys.mjs" {file: "resource://gre/modules/PartitioningExceptionListService.sys.mjs" line: 88}]

1721838142295   addons.xpi  WARN    Addon with ID undefined already installed, older version will be disabled

[JavaScript Error: "Error: Addon must include an id, version, and type" {file: "resource://gre/modules/addons/XPIProvider.jsm" line: 1723}]

[JavaScript Error: "Error: Addon must include an id, version, and type" {file: "resource://gre/modules/addons/XPIProvider.jsm" line: 1723}]

[JavaScript Error: "uncaught exception: undefined"]

[JavaScript Error: "Passing a URI to Zotero.File.getContentsAsync() is deprecated -- use Zotero.HTTP.request() instead"]

[JavaScript Error: "Passing a URI to Zotero.File.getContentsAsync() is deprecated -- use Zotero.HTTP.request() instead"]

[JavaScript Error: "TypeError: this.editorView is undefined" {file: "resource://zotero/note-editor/editor.js" line: 6}]

appName => Zotero, version => 7.0.0-beta.105+c5c613c82, os => Windows 10.0 19045, locale => en-US, extensions => Better Notes for Zotero (1.1.4-beta.106, extension), OpenH264 Video Codec provided by Cisco Systems, Inc. (1.8.1.2, plugin), Widevine Content Decryption Module provided by Google Inc. (4.10.2710.0, plugin), Zotero Scholar Citations (2.0.4, extension, disabled), ZoteroQuickLook (1.4.2, extension, disabled), Propachi: monkey-patch for Zotero CSL processor (Uppercase subtitles version) (1.1.90, extension, disabled), Zotero Scihub (0.0.6, extension, disabled), Zutilo Utility for Zotero (3.10.0, extension, disabled), ODF Scan for Zotero (2.0.48, extension, disabled), Sci-Hub Plugin for Zotero (1.4.4, extension, disabled), zotxt (6.0.2, extension, disabled), Zotero Memento (1.1.1, extension, disabled), ZoteroPreview (0.1.6, extension, disabled), ZoteroSpecialTagsColumn (0.0.5, extension, disabled), Storage Scanner for Zotero (5.0.12, extension, disabled), Zotero Citation Counts Manager (1.3.0, extension, disabled), Background for Zotero Pdf Reader (0.0.1, extension, disabled), Duplicates Merger for Zotero (1.1.5, extension, disabled), Folder Import for Zotero (0.0.5, extension, disabled), ZoteroAbstractCleaner (0.0.7, extension, disabled), ZotFile (5.1.2, extension, disabled), Zotero PDF Preview (0.3.7, extension, disabled), Zotero Update IFs (0.95.6, extension, disabled), Cita (0.5.5, extension, disabled), Zotodo (0.10.0, extension, disabled), Wandering File (0.2.8, extension, disabled), Del Item With Attachment (0.3.2, extension, disabled), Actions and Tags for Zotero (1.0.0-beta.44, extension, disabled), Zotero OCR (0.7.3, extension, disabled), MarkDB-Connect (0.1.1, extension, disabled), Better BibTex for Zotero (6.7.212, extension, disabled), PDF Figure (0.2.4, extension, disabled), Green Frog (0.19.03, extension, disabled), Add-on Market for Zotero (1.6.2, extension, disabled), Jasminum (1.0.0-16, extension, disabled), Zoplicate (3.0.3, extension, disabled), Sci-PDF (1.1.1, extension, disabled), Chartero (2.9.3, extension, disabled), Ethereal Reference (0.9.4, extension, disabled), Translate for Zotero (1.1.0-beta.56, extension, disabled), Zotero Debug Bridge (51.0, extension, disabled), zotero-annotation-manage (0.6.110, extension, disabled), Ethereal Style (4.6.3, extension, disabled), Awesome GPT (1.0.8, extension, disabled)

Anything else?

No response

saccohuo commented 1 month ago

[JavaScript Error: "Passing a URI to Zotero.File.getContentsAsync() is deprecated -- use Zotero.HTTP.request() instead"] There are some URI in my notes, and I wanna handle the URI in template editor. Can the plugin just report a warning instead of an error?

windingwind commented 1 month ago

Not sure what you mean by saying There are some URI in my notes, and I wanna handle the URI in template editor.

What kind of template are you using, and why do you think this error is related to a certain note template? Could you please share the template you use that causes the error?

saccohuo commented 1 month ago

After I delete the line, it works, but why? <p><img data-attachment-key="F5GBNPMY" >&nbsp;</p>

windingwind commented 1 month ago

Please see my reply above: we need to know what kind of template you are using and how you are using them. If it's a problem with the note template, then basically it is not a bug with the plugin.

saccohuo commented 1 month ago

I am using [ExportMDFileContent] template, and settings in template is as follows.

${{
    return mdContent
        .replace(/\n{3,}/g, '\n\n')  // 将三个或更多换行替换为两个换行
        .replace(/([^\n])\n\n([^\n#])/g, '$1\n$2')  // 保留标题前的空行,但去除其他地方的多余换行
        .replace(/!\[\]\(data:image\/png;base64,[A-Za-z0-9+/=]+\)\n?/g, '')  // 移除 base64 编码的图片行
        .trim();  // 移除开头和结尾的空白字符
}}$

I find just need to change the data-sttachment-key in <p><img data-attachment-key="F5GBNPMY" >&nbsp;</p> to a exist foldername in storage path, then it works well. Can you tell me more about what does the plugin do to check data-sttachment-key? Many thanks.

windingwind commented 1 month ago

Don't modify this attribute. Any modification may cause the syncing to fail. The plugin should take over the images in the markdown to keep in sync with the note item in Zotero.

I find just need to change the data-sttachment-key in \<p>\<img data-attachment-key="F5GBNPMY" >\ \</p> to a exist foldername in storage path, then it works well.

Why's that?

saccohuo commented 1 month ago

I don't know why either, and I am trying to figure it out.

windingwind commented 1 month ago

I mean, why do you want to manually replace them? Aren't the images already be available in the markdown file exported by the plugin?

windingwind commented 1 month ago

To be clear, I was talking about:

There are some URI in my notes, and I wanna handle the URI in template editor.

I still don't understand what URI you want to handle and how/why you want to do it.

saccohuo commented 1 month ago

Image URI is base64 data extracted from png. For example:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAAAcCAMAAABF0y+mAAABPlBMVEX////E6OyQ091uwtFjt8tvs8uRvNLE1+Sk4+UwxssWvMcTtcMPrb8NoroLlbYAhbEAdayRss5o19U/zc4bjLQagbEAZagbaqnd5u9Z1dMYea4Ub6wAUKDQ3eqk5+IAX6YAWaXy9fmA3thLtMecytmzx9yQq81Dd7GpvNXO8e9ty9O77OmM3tl009H+4tn+xLr+tLD9sLr+zNb+8/bR0sf/pX3/iVD+jlv+gWr9f3f+cHv/Zn//YIv+SoT9e6j+6PHvkmH+jWX/WI//UJX9L5H9u9mu19j/i1L+R579HJj+PKf6FqLK3dz9gZT5j8z9zbL8r5P8MbL91sP+ewXit6T9o77/TZf6AK3/gz382u7+gy3+RZ/9q3791eD8k7L+Oqj6Sbj9wKH8uN//VZH+r6T+lZL+fW/+dHX+i2n8aaE/3YaXAAABZ0lEQVR4AWIgEjAyMbOwsrED2qIHLAdiAACgfdzatm1kattuauv+F9iM6pn4x/lFTBabw+XxBUKh6MvEEgmBUplQrlB+mEoiYbEJVGvkWt2r6cUqFYkCtVBuMGpNL2gWiwm0WP+USp3N7nA+zWU24+g2/dqpx4tUwvwhBHrNPi+D4Q8EQ6Fw5B1der3XF40BLJ5IptKZbO4VTUwm05sHWIHAYqlceVWPp8qs1R5Yb7yqq1qtghdstl4XbrerGI7BYCdDYJeCSA+t2m7HQK2PV8MZhIMBhcMRMXQMMLI+mSKcUTvujXq4RmGfrOcInNMjF3im7FMYmS6f6B8tVsRp/WR9TSC93cWCmJj+NtPldrCja/sRXOwfts4gbB0edbiAsDYky6HMESE9kFgVQgBBrH86oxtC2MgxXnQBAcCwwuVKYHnOeP0iGESPckvgmLkT416/YQGC2+WaSmXDn0SM9g8DgfXrc/wDaw5R0gcZRUEAAAAASUVORK5CYII=

The original idea is to show image in Zotero notes as URI format, because it cannot show the area annotation as image type in the note.

windingwind commented 1 month ago

because it cannot show the area annotation as image type in the note.

I don't understand. What's image type?

Parsing images to base64 in the exported markdown file would definitely break the syncing. This isn't the correct way to use the plugin.

saccohuo commented 1 month ago

Yes, I get the right way to transform area annotation to image, use the importEmbeddedImage function in zotero-better-notes/src/utils/note.ts, rather than URI format. Many thanks.