Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
create notebook's "root note" for ENEX import
azivnerb8eaff055ab1
diff --git a/README.md b/README.mdindex 905976d7f1..c4272cbd71 100644--- a/README.md+++ b/README.md@@ -21,7 +21,7 @@ See other pictures in [screenshot tour](https://github.com/zadam/trilium/wiki/Sc* [Scripting](https://github.com/zadam/trilium/wiki/Scripts) - see [Advanced showcases](https://github.com/zadam/trilium/wiki/Advanced-showcases)* Scales well in both usability and performance upwards of 100 000 notes* [Night theme](https://github.com/zadam/trilium/wiki/Themes)-* [Markdown import & export](https://github.com/zadam/trilium/wiki/Markdown)+* [Evernote](https://github.com/zadam/trilium/wiki/Evernote-import) and [Markdown import & export](https://github.com/zadam/trilium/wiki/Markdown)## Buildsdiff --git a/src/services/enex.js b/src/services/enex.jsindex 41335990c8..3b706b0972 100644--- a/src/services/enex.js+++ b/src/services/enex.js@@ -22,6 +22,16 @@ async function importEnex(file, parentNote) {const xmlBuilder = new xml2js.Builder({ headless: true });const parser = new xml2js.Parser({ explicitArray: true });+ const rootNoteTitle = file.originalname.toLowerCase().endsWith(".enex")+ ? file.originalname.substr(0, file.originalname.length - 5)+ : file.originalname;++ // root note is new note into all ENEX/notebook's notes will be imported+ const rootNote = (await noteService.createNote(parentNote.noteId, rootNoteTitle, "", {+ type: 'text',+ mime: 'text/html'+ })).note;+// we're persisting notes as we parse the document, but these are run asynchronously and may not be finished// when we finish parsing. We use this to be sure that all saving has been finished before returning successfully.const saveNotePromises = [];@@ -195,7 +205,7 @@ async function importEnex(file, parentNote) {// following is workaround for this issue: https://github.com/Leonidas-from-XIV/node-xml2js/issues/484content = extractContent(xmlObject['en-note']);- const resp = await noteService.createNote(parentNote.noteId, title, content, {+ const resp = await noteService.createNote(rootNote.noteId, title, content, {attributes,dateCreated,type: 'text',@@ -234,8 +244,7 @@ async function importEnex(file, parentNote) {return new Promise((resolve, reject) =>{// resolve only when we parse the whole document AND saving of all notes have been finished- // we resolve to parentNote because there's no single note to pick- saxStream.on("end", () => { Promise.all(saveNotePromises).then(() => resolve(parentNote)) });+ saxStream.on("end", () => { Promise.all(saveNotePromises).then(() => resolve(rootNote)) });const bufferStream = new stream.PassThrough();bufferStream.end(file.buffer);