stefanopagliari / bibnotes

358 stars 30 forks source link

Image Import Path #73

Closed 133501 closed 2 years ago

133501 commented 2 years ago

When trying to import and copy images from my zotero notes:

Zotero v.: 6.0.5-beta.2+c510d9146 bibnotes: 0.9.13

iShareStuff commented 2 years ago

i modify the code, you can use this or see the video at https://www.bilibili.com/video/BV1k34y1v7fY/ bibnotes-ShareStuff.zip

stefanopagliari commented 2 years ago

@133501 In the settings it is possible to specify the folder where the images are stored Screenshot 2022-04-20 at 16 42 06

hpxing commented 2 years ago

it works ok

133501 commented 2 years ago

@iShareStuff thanks for the suggestion. It works that way, but it is a partial solution. If I have bibnotes NOT to copy the images - plugin creates a link to specified Zotero folder and images display.

But if I want the bibnotes copy images to my vault - I specify the folder from where to take them e.g. D:\hajek\.... The problem is that bibnotes (?) assumes that folder is located on C drive and does the C:\D:\hajek\ instead of just D:\hajek. And it does that only when copying the images - for creating links to them it specifies the path correctly.

I've tested with the latest release.

doomgutt commented 2 years ago

I second @133501's situation. For me the plugin also throws an issue about a "wrong path" even when the specified path to Zotero/storage is correct. The issue, however, does not arise for me when I import my PDFs back into Zotero.

I believe what is happening is that the plugin assumes that the path of the PDF is the path where the images should be stored, so if the PDF is stored externally as a link, the plugin tries to look for the image there.

I tried looking for the place in the code where those variables are assigned but I'm not good enough with JS and don't have enough time to patch it myself.... hopefully the devs can patch it, I'm assuming it's just a path variable assignment bug.

EDIT: I think the issue is here: https://github.com/stefanopagliari/bibnotes/blob/69a9ee472632f50f69797e68e8e43a6e1211b8b2/src/main.ts#L1101 (or line ~3463 in the merged main.js)

I don't know enough JS to fix the situation well, but it seems that replacing this.pathZoteroStorage with this.settings.zoteroStoragePathManual does since, as I suspected, the plugin was disregarding the manual path input.

To fix it well there probably needs to be some if statement about whether that option is empty or not, I duno.

Anyways, I hope this helps users/creator.

P.S. amazing plugin, best reference transfer plugin I have seen and I've spent a few weeks now trying to make one work well. Big thanks to the creator.

stefanopagliari commented 2 years ago

@doomgutt thank you for looking into this. I think you have identified the issue. I have fixed it in the latest release https://github.com/stefanopagliari/bibnotes/releases/tag/0.9.152.

Could you please test it and let me know if it solves the issue?

doomgutt commented 2 years ago

Yeah, looks to be working now:) Thank you very much for maintaining this plugin

133501 commented 2 years ago

@doomgutt thank you for looking into this. I think you have identified the issue. I have fixed it in the latest release https://github.com/stefanopagliari/bibnotes/releases/tag/0.9.152.

Could you please test it and let me know if it solves the issue?

Hello @stefanopagliari! I'm afraid the latest version did not fix the bug. At least for me. In Obsidians console I still get the error:

Uncaught Error: ENOENT: no such file or directory, copyfile 
'D:\hajek\.......\zotero\storage\YZ9WNXMY\image.png' 
->
 'C:\D:\hajek\........\Zotero-betterbibtex\media\zimmermann-2002-ventcontrolmeans_YZ9WNXMY.png'

Where the first path is correct, but the second one is obviously not with the double drive statement 'C:\D:\...

stefanopagliari commented 2 years ago

@133501, what is the value that you have added in the settings field "Zotero Local Folder"? If you could activate the debug mode in the settings and send me the text file generated that would be helpful

133501 commented 2 years ago

@stefanopagliari it is: D:\hajek\GD133501\s_\zotero\storage\ debugout.txt

Thank you for looking into this! I realize it is not vital and not copying images is also fine.

stefanopagliari commented 2 years ago

@133501 Thank you. I will try to fix this. It is not the first time that I encounter problems in dealing with file paths across windows and Mac. The main obstacle is that I do not have a computer running windows, which makes testing any fix complicated.

stefanopagliari commented 2 years ago

@133501 Would you be able to download this main.js file, replace the existing one in the plugin directory and share the console log when running the usual extract? https://www.icloud.com/iclouddrive/01bZLw93HEc_KAU_Or1pPL88g#main

133501 commented 2 years ago

@stefanopagliari I see. I'm glad to help! I've set up a test Vault on my home computer to test this. Please be aware that the drive letters are different. Nevertheless, the error is still the same - adding an extra C:\ to the actual correct path. console-testVault.txt debugout-testVault.txt

stefanopagliari commented 2 years ago

@133501 Thank you. I'm trying to figure out what is adding "c:\" in front of the correct path.

At line 4664 and 4669 the old and the new path seem to be correct plugin:bibnotes:4664 pathImageOld: G:\Můj disk\s\zotero\storage\YZ9WNXMY\image.png plugin:bibnotes:4669 pathImageNew: G:\Můj disk\p\obsidian-sync\testVault\bib-export\media\zimmermann-2002-ventcontrolmeans_YZ9WNXMY.png

but shortly later the function copying the file from the old to the new path through this error: plugin:bibnotes:4680 Uncaught Error: ENOENT: no such file or directory, copyfile 'G:\Můj disk\s\zotero\storage\YZ9WNXMY\image.png' -> 'C:\G:\Můj disk\p\obsidian-sync\testVault\bib-export\media\zimmermann-2002-ventcontrolmeans_YZ9WNXMY.png'

stefanopagliari commented 2 years ago

if you don't mind, could you replace the main.js file with the one at this link and share the console.log? https://www.icloud.com/iclouddrive/0a5d9yx6GIeXn51-eat7cN3aA#main it will not solve the issue but it will print out a couple of additional logs

133501 commented 2 years ago

@stefanopagliari here they are: console-testVault.txt debugout-testVault.txt

I'm no programmer but.... Am I correct that this is where the images get copied?

              if (!fs2.existsSync(pathImageNew)) {
                fs2.copyFile(pathImageOld, pathImageNew, (err) => {
                  if (err)
                    throw err;

because before there I can find only these parts where pathImageNew is used:

          pathImageNew = import_path2.default.normalize(import_path2.default.format({
            dir: (0, import_obsidian6.normalizePath)(this.app.vault.adapter.getBasePath() + "\\" + this.settings.imagesPath),
            base: citeKey + "_" + lineElements.imagePath + ".png"
          }));
          if (this.zoteroBuildWindows != true) {
            pathImageNew = "/" + pathImageNew;
          }
          if (this.zoteroBuildWindows == true) {
            const regexbackslash = /\\/g;
            pathImageNew = pathImageNew.replace(regexbackslash, "\\\\");

And the only thing I can see is that the pathImageNew is assigned with some kind of function import_obsidian6, but the setting of the actual path in setting section uses import_obsidian5 here:

      if (settings.imagesCopy) {
        new import_obsidian5.Setting(importImages).setName("Image Import Path").setDesc("Add the relative path to the folder inside your vault where the image will be copied").addSearch((cb) => {
          new FolderSuggest(this.app, cb.inputEl);
          cb.setPlaceholder("Example: folder1/folder2").setValue(this.plugin.settings.imagesPath).onChange((new_folder) => __async(this, null, function* () {
            settings.imagesPath = new_folder;
            yield plugin.saveSettings();
          }));
        });
      }

Could that be it?

stefanopagliari commented 2 years ago

@133501 The plugin is coded in typescript. This generates a javascript file, which is the one I shared.

Could you try this? https://www.icloud.com/iclouddrive/0cfjQ3BXC3aZq21QSp3ky3Kqw#main Thank you for helping me solve this

133501 commented 2 years ago

@stefanopagliari here they are: console-testVault.txt debugout-testVault.txt

nono, I thank you for solving this!

stefanopagliari commented 2 years ago

Sorry, one more,: https://www.icloud.com/iclouddrive/06bnYNxz_9mRj3Nb9-dzPNtbw#main

133501 commented 2 years ago

@stefanopagliari you are the man! :) The Image gets imported without the error. THANK YOU SO VERY MUCH! console-testVault.txt debugout-testVault.txt

stefanopagliari commented 2 years ago

Great. I've pushed the changes to the new version https://github.com/stefanopagliari/bibnotes/releases/tag/0.9.154