zadam / trilium

Build your personal knowledge base with Trilium Notes
GNU Affero General Public License v3.0
26.73k stars 1.86k forks source link

(Feature request) ETAPI interface to get note content hash #4005

Open mm21 opened 1 year ago

mm21 commented 1 year ago

Describe feature

Hi,

I'm building a tool to synchronize Trilium with a locally-maintained note tree, and it would really help to be able to get the hash of a note's current content. That way someone could check if the local file is already in sync with Trilium, without downloading the content or just blindly updating it every time.

This will become more important later as I intend to build a photo manager and efficiently track thousands of photos using Trilium. (Imagine syncing a folder of photos and being able to tag people/places just by setting a relation, with labels automatically populated by the photo's exif data. But I digress...)

I see the hash is already computed in BNote.setContent(), can that be readily accessed by ETAPI? Base64-encoded SHA1 is perfect.

Thanks for considering!

Additional Information

No response

zadam commented 1 year ago

I've added "blobId" to the ETAPI interface in 0.61. For note types which are "copy on write", this effectively represents a content hash. It might not cover your needs completely, as for some notes (text notes), this doesn't change.

mm21 commented 1 year ago

Thanks, this will work for binary notes which was my main concern. To accommodate text notes, can forceCold be added as a parameter to putNoteContentById? Then when I set content during a sync, I'll always pass forceCold to generate the blobId for the next sync.

zadam commented 1 year ago

Actually, your comment got me thinking and I reworked this to behave uniformly - blobId will be effectively a content hash for all types of notes.

mm21 commented 1 year ago

Nice, thanks a lot!

maphew commented 4 months ago

re: https://github.com/zadam/trilium/issues/4005#issuecomment-1581558060 is there remaining work to finish this off? if so please specify what's left and maybe someone will pick it up (perhaps even me if I can come up to speed).