Erallie / diarian

All-in-one journaling toolkit.
MIT License
41 stars 2 forks source link

[Feature request] Replace/Do Not Replace existing images #67

Open Cossackx opened 2 months ago

Cossackx commented 2 months ago

When importing a .zip, it add the same images repeatedly but with different name (File, File 1, File 2, ...). If I am doing this daily the vault gets bloated quickly.

Is this something I'm doing wrong or by design?

Erallie commented 2 months ago

@Cossackx Can you tell me what settings you're using for the importer?

Cossackx commented 2 months ago

Here are my settings:

image

image

image

image

Erallie commented 2 months ago

@Cossackx May I ask what your daily notes settings looks like too? How does the Settings → Daily notes → Date format look like?

Erallie commented 2 months ago

@Cossackx ohh... I think I understand what you're saying... If you are importing a journal multiple times, and each time, it re-imports the same attachments, but just renames the attachment if it already exists?

So it only imports the attachments for the entries it belongs to, but at the same time, it imports the images again even if it already exists?

Erallie commented 2 months ago

Oh wait sorry I understand no I was thinking you were using different settings.

Erallie commented 2 months ago

@Cossackx If you use the setting Import journal → How to handle duplicate notes → Append all new entries, it will re-attach each attachment at the end of all the entries.

If you have multiple notes per day, I recommend following these instructions to separate your entries into multiple notes before using the importer. Then, you can potentially clear your journal folder to remove the old entries, and each time you re-import it, you can use the setting Import journal → How to handle duplicate notes → Keep last entry (overwrite), and it should overwrite the old entries with any changes you've made in Diarium (if you're still importing from Diarium).

Because if you are using the setting How to handle duplicate notes → Append all new entries, every time you import your journal, it will just re-add everything (including the attachments) to the end of what you have.

Given, if you re-import the journal every day using How to handle duplicate notes → Keep last entry (overwrite), I get that it will still re-import the new image while adding it as a new attachment to the note... maybe I can add an option to delete attachments in the overwritten note before uploading the new one?

If you use the setting How to handle duplicate notes → Keep first entry (don't overwrite), it won't import any new attachments. So that should already be handled.

Is this in line with what you are saying? Not sure I'm addressing it completely.

Cossackx commented 2 months ago

Appending to my existing templater daily note {YYYY-MM-DD} works great.

In Diariun, I can add photos to my day, let's say it's named "Day1_Image". Great. When I import, I get the photos while the notes append to the daily note. Perfect...

The next day, I want to do a new import because I have a new daily note with another image, let's call it "Day 2_Image." The daily notes work great but I now have 3 images: "Day1_Image, Day2_Image, Day1_Image 1."

So the next day would end up with: "Day1_Image, Day2_Image, Day1_Image 1, Day1_Image 2, Day2_Image, Day2_Image 1, Day3_Image."

It is Adding and Duplicating the pictures each import (bug?). Daily note gets Appended (feature).

Note sure if there is a way to only update days since last import? Or Overwrite Images with same images (could be dangerous)?

Cossackx commented 2 months ago

Appending to my existing templater daily note {YYYY-MM-DD} works great.

In Diariun, I can add photos to my day, let's say it's named "Day1_Image". Great. When I import, I get the photos while the notes append to the daily note. Perfect...

The next day, I want to do a new import because I have a new daily note with another image, let's call it "Day 2_Image." The daily notes work great but I now have 3 images: "Day1_Image, Day2_Image, Day1_Image 1."

So the next day would end up with: "Day1_Image, Day2_Image, Day1_Image 1, Day1_Image 2, Day2_Image, Day2_Image 1, Day3_Image."

It is Adding and Duplicating the pictures each import (bug?). Daily note gets Appended (feature).

Note sure if there is a way maybe to only update days since last import? Or Overwrite Images with same images (could be dangerous)?

Erallie commented 2 months ago

@Cossackx ahh okay so the images aren't being attached to the pre-existing note, but there's just another image in your vault that's not attached to any notes when you re-import?

I don't think I'm completely understanding your setup? Can you maybe post an image (or multiple images) showing what you're talking about? You can obscure the text and blur the images to keep your entries private. In any daily notes, I'd just need to see any horizontal rules between entries within a note and where any images are within the notes themselves.

I understand how Diarium works because I made this plugin to migrate my own journal entries from Diarium to Obsidian. So the feature for attachments I implemented myself in the importer. I feel like this has to do with using getAvailablePathForAttachment() to import the images, but I don't think I completely understand which thing is happening that is the issue. Is it attaching the images multiple times to the same entry? Or does the entry still have just the one image but replaces the image that's already there with a newly uploaded image? And does the rest of the entry already look the same? Or are the entries also being repeated multiple times?

Erallie commented 2 months ago

I guess the reason I'm asking is because if you are re-importing a journal from Diarium, and don't want to touch the entries that are already there, it's best to use the option How to handle duplicate notes → Keep first entry (don't overwrite) because that won't touch any existing entries that are already in your vault; it will only add new entries.

But that also means you can't import more than one entry per day.

Erallie commented 2 months ago

Unless of course you include the time in the note, like in the instructions

Cossackx commented 2 months ago

The daily note goes into one folder and images go into the attachment folder. Daily notes get appended. Images get duplicated but I will try this again (Keep first entry (don't overwrite) ) and report back.

Cossackx commented 2 months ago

OK. Tests complete. Same behaviors happening.

Tested overwrite and don't overwrite. Thats great for either replacing or not replacing files but not exactly what trying to do.

Append the Daily note is working, but with some duplications, some of which makes sense...

  1. I import and append to an existing daily note, it adds to the end of the file. Not perfect, but I accept since I'm not sure if replacement is possible. image

  2. If your Diariun has a picture in it, it appends that as well, which then comes with another image in the attachment folder but since there is already on there, it duplicates with a rename. image

Maybe there can be something in the code that checks for existing photo with the same name. If found, skip not next photo in Diariun?

Erallie commented 2 months ago

@Cossackx My question is, why don't you just create a different note for each entry? I made the importer with the intent of it only being used once. I've referenced the instructions to do so multiple times, but you didn't really respond to it. All you need to do is add the time to the Daily note format, and then you won't need to append your daily notes each time, but you can just use Keep entry (don't overwrite) and it should only import new entries. Or alternatively use Keep last entry (overwrite) and it should replace all old entries with the new ones. But again, you need to have your settings set to allow for multiple notes per day for it to keep all your entries. Which is why I'm asking.

If there's a good reason for you not using multiple notes per day, I'd be willing to consider adding features for it for the case of re-importing your vault daily. But I'd need to understand what you're trying to do to compensate for it.

Cossackx commented 2 months ago

Interesting - or I may be misunderstanding. My workflow is each day to get a new "Daily Note" for which I have a templater template for with properties and headers. This is similar to the template option available in Diarium. Throughout the day, I use QuickAdd on a hotkey to jot down notes and put them in in the daily note directly in a section for "# Notes" that appends my entry along with a timestamp. Or I open the file up directly and jot down entries. So, using my example picture above, the daily note would contain Note Entry 1, Note Entry 2, Note Entry 3. If each entry were its own file/note, that would unnecessarily bloat my vault and add friction to my workflow.

Now, I noticed that I could set a date range for the import, which then does not include older daily notes and images. This could be done just once at the end of the day.

Erallie commented 2 months ago

@Cossackx Ahh okay. Now that makes sense.

I originally created Diarian's importer to be used just once at the beginning of vault setup. I could potentially attempt to create a way to scan pre-existing notes to try to determine if a note being imported already exists, but that may be a bit difficult to implement. I'll consider adding this feature in the future, but for the meantime, do you think that just importing a specific date range from Diarium would be a good workaround?

I just need to find out good ways to implement it.

As for attachments, I could potentially try to implement something that just doesn't re-import attachments if an attachment with that name already exists within your set attachments folder, but that means if you have an attachment with the same name on different days, but they both end up in the same folder in your vault, it won't import or attach it the second time it's referenced. So maybe I can just add an option for that and made a toggle so that people can trigger it on and off. The entries though would be more difficult, since I would need to compare text.

Cossackx commented 2 months ago

Ahh. Now I understand your intent/vision for this plugin. Since Diarium is easy to use on iOS compared to Obsidian, I was thinking use Diarium throughout the day and then import into Obsidian nightly or weekly.

  1. "I'll consider adding this feature in the future, but for the meantime, do you think that just importing a specific date range from Diarium would be a good workaround?"

...I'll test it out and let you know.

  1. "As for attachments..." I see what you are saying. A little more complicated with appending the daily notes.

I think your work is amazing. I have no coding skills so it's not lost on me that this is a labor of love and I wouldn't even know where to start. I appreciate you!