ozntel / obsidian-link-converter

Obsidian Plugin to scan all your links in your vault and convert them to your desired format.
173 stars 14 forks source link

Converter running on Vault or Folder modifies non-markdown files as well #5

Closed vishnraj closed 2 years ago

vishnraj commented 2 years ago

Hi,

This is a good idea for a tool and one of the few I could find in community extensions for Obsidian that does replacements in bulk.

The issue with the tool, at least from what I experienced is when run on an entire vault or a folder within a vault, it doesn't check whether the files it's running the replacement on are markdown files.

I ran this on my vault and then folders within it, after thinking it didn't work on the vault and then noticed my PNG files were corrupted; timestamps on them were updated before and after running the tool on the given subdirectory.

I think this will be frustrating for other users as it was for me when they realized their images for their notes are corrupted after running with the vault/folder options.

Take a look when you get a chance,

Thanks

ozntel commented 2 years ago

The plugin converts all internal links. Not only markdown notes. Each time plugin actually checks if the file exists in the vault.

Please give me a sample. I need to see what your original link was and what the final output is after the conversion

vishnraj commented 2 years ago

It's difficult to post the exact example, because I cannot login to standard GitHub on my work laptop to post the changes, but yeah it's more the fact that it even runs on non-markdown files, since that seems like it wouldn't really be necessary given in Obsidian, internal links are going to only be primarily in markdown files. At the least, I don't think this extension should be running on media file/attachments (filter out jpgs, pngs etc), since there wouldn't be valid links in those files to search for.

vishnraj commented 2 years ago

I suppose I can recreate this on my personal laptop.

ozntel commented 2 years ago

Oh I see what you mean. It is a bug that I haven't realized before. Thank you for noticing this and I'm sorry if it broke anything. Let me correct it now and publish a new version.

ozntel commented 2 years ago

Ok released the new version with the fix. Please let me know if you realize anything wrong after the update

vishnraj commented 2 years ago

Ok released the new version with the fix. Please let me know if you realize anything wrong after the update

I appreciate the fix in the new version and I checked the change and tried it on a different machine, it does indeed fix the problem going forward.

Now, on my other machine with the changed files, I'm seeing if there is any way to undo the changes.

At first I thought it was causing replacements via the regex find/replace for the links, but noticing, I don't think the PNG files would be affected by that, instead I think they are getting saved in a different format. Running twice on the same set of PNG files has no affect, so my guess is format of data is being changed and looking at the files in text form, it appears to be the case as well.

If you have any info on what format the old code would have saved the PNG files to, it would be greatly appreciated, as it would allow me to undo the change.

vishnraj commented 2 years ago

I don't think the files can be fixed easily: https://stackoverflow.com/questions/26712824/is-it-possible-to-fix-png-files-corrupted-by-ascii-conversion My guess is the data was saved as an ASCII encoded string and that cannot be easily undone back to a PNG.

I will have to just delete them and gather them again and going forward, I guess this won't be an issue.

ozntel commented 2 years ago

I will have to just delete them and gather them again and going forward, I guess this won't be an issue.

Most probably it is the only way. I'm sorry for such inconvenience. I missed this within the previous release, in which I added an option for converting links in a certain folder.

I generally save my files on onedrive and it is possible to revert back there from version history. I strongly recommend using such service going forward. It might be helpful in many cases.

vishnraj commented 2 years ago

I will have to just delete them and gather them again and going forward, I guess this won't be an issue.

Most probably it is the only way. I'm sorry for such inconvenience. I missed this within the previous release, in which I added an option for converting links in a certain folder.

All good, as it turns out, not all the files were corrupted, so all was not lost. Thanks!