mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
create notebook's "root note" for ENEX import
This commit is contained in:
parent
5e318c6242
commit
b8eaff055a
@ -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)
|
* [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
|
* Scales well in both usability and performance upwards of 100 000 notes
|
||||||
* [Night theme](https://github.com/zadam/trilium/wiki/Themes)
|
* [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)
|
||||||
|
|
||||||
## Builds
|
## Builds
|
||||||
|
|
||||||
|
@ -22,6 +22,16 @@ async function importEnex(file, parentNote) {
|
|||||||
const xmlBuilder = new xml2js.Builder({ headless: true });
|
const xmlBuilder = new xml2js.Builder({ headless: true });
|
||||||
const parser = new xml2js.Parser({ explicitArray: 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
|
// 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.
|
// when we finish parsing. We use this to be sure that all saving has been finished before returning successfully.
|
||||||
const saveNotePromises = [];
|
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/484
|
// following is workaround for this issue: https://github.com/Leonidas-from-XIV/node-xml2js/issues/484
|
||||||
content = extractContent(xmlObject['en-note']);
|
content = extractContent(xmlObject['en-note']);
|
||||||
|
|
||||||
const resp = await noteService.createNote(parentNote.noteId, title, content, {
|
const resp = await noteService.createNote(rootNote.noteId, title, content, {
|
||||||
attributes,
|
attributes,
|
||||||
dateCreated,
|
dateCreated,
|
||||||
type: 'text',
|
type: 'text',
|
||||||
@ -234,8 +244,7 @@ async function importEnex(file, parentNote) {
|
|||||||
return new Promise((resolve, reject) =>
|
return new Promise((resolve, reject) =>
|
||||||
{
|
{
|
||||||
// resolve only when we parse the whole document AND saving of all notes have been finished
|
// 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(rootNote)) });
|
||||||
saxStream.on("end", () => { Promise.all(saveNotePromises).then(() => resolve(parentNote)) });
|
|
||||||
|
|
||||||
const bufferStream = new stream.PassThrough();
|
const bufferStream = new stream.PassThrough();
|
||||||
bufferStream.end(file.buffer);
|
bufferStream.end(file.buffer);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user