mirror of
https://github.com/zadam/trilium.git
synced 2025-11-18 03:00:41 +01:00
allow import of multiple files at the same time
This commit is contained in:
@@ -298,12 +298,7 @@ async function importEnex(importContext, file, parentNote) {
|
||||
return new Promise((resolve, reject) =>
|
||||
{
|
||||
// resolve only when we parse the whole document AND saving of all notes have been finished
|
||||
saxStream.on("end", () => { Promise.all(saveNotePromises).then(() => {
|
||||
importContext.importFinished(rootNote.noteId);
|
||||
|
||||
resolve(rootNote);
|
||||
});
|
||||
});
|
||||
saxStream.on("end", () => { Promise.all(saveNotePromises).then(() => resolve(rootNote)) });
|
||||
|
||||
const bufferStream = new stream.PassThrough();
|
||||
bufferStream.end(file.buffer);
|
||||
|
||||
@@ -64,8 +64,6 @@ async function importOpml(importContext, fileBuffer, parentNote) {
|
||||
returnNote = returnNote || note;
|
||||
}
|
||||
|
||||
importContext.importFinished(returnNote.noteId);
|
||||
|
||||
return returnNote;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ async function importMarkdown(importContext, file, parentNote) {
|
||||
});
|
||||
|
||||
importContext.increaseProgressCount();
|
||||
importContext.importFinished(note.noteId);
|
||||
|
||||
return note;
|
||||
}
|
||||
@@ -36,7 +35,6 @@ async function importHtml(importContext, file, parentNote) {
|
||||
});
|
||||
|
||||
importContext.increaseProgressCount();
|
||||
importContext.importFinished(note.noteId);
|
||||
|
||||
return note;
|
||||
}
|
||||
|
||||
@@ -386,8 +386,6 @@ async function importTar(importContext, fileBuffer, importRootNote) {
|
||||
}
|
||||
}
|
||||
|
||||
importContext.importFinished();
|
||||
|
||||
resolve(firstNote);
|
||||
});
|
||||
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
|
||||
const messagingService = require('./messaging');
|
||||
|
||||
// importId => ImportContext
|
||||
const importContexts = {};
|
||||
|
||||
class ImportContext {
|
||||
constructor(importId, safeImport) {
|
||||
// importId is to distinguish between different import events - it is possible (though not recommended)
|
||||
@@ -15,6 +18,15 @@ class ImportContext {
|
||||
this.lastSentCountTs = Date.now();
|
||||
}
|
||||
|
||||
/** @return {ImportContext} */
|
||||
static getInstance(importId, safeImport) {
|
||||
if (!importContexts[importId]) {
|
||||
importContexts[importId] = new ImportContext(importId, safeImport);
|
||||
}
|
||||
|
||||
return importContexts[importId];
|
||||
}
|
||||
|
||||
async increaseProgressCount() {
|
||||
this.progressCount++;
|
||||
|
||||
@@ -29,14 +41,6 @@ class ImportContext {
|
||||
}
|
||||
}
|
||||
|
||||
async importFinished(noteId) {
|
||||
await messagingService.sendMessageToAllClients({
|
||||
importId: this.importId,
|
||||
type: 'import-finished',
|
||||
noteId: noteId
|
||||
});
|
||||
}
|
||||
|
||||
// must remaing non-static
|
||||
async reportError(message) {
|
||||
await messagingService.sendMessageToAllClients({
|
||||
|
||||
Reference in New Issue
Block a user