mirror of
https://github.com/zadam/trilium.git
synced 2025-01-17 20:48:12 +08:00
import error handling
This commit is contained in:
parent
e4c78f3887
commit
a097cefba7
3 changed files with 37 additions and 17 deletions
|
@ -63,6 +63,12 @@ function importIntoNote(importNoteId) {
|
|||
}
|
||||
|
||||
messagingService.subscribeToMessages(async message => {
|
||||
if (message.type === 'import-error') {
|
||||
infoService.showError(message.message);
|
||||
$dialog.modal('hide');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!message.importId || message.importId !== importId) {
|
||||
// incoming messages must correspond to this import instance
|
||||
return;
|
||||
|
|
|
@ -9,6 +9,7 @@ const messagingService = require('../../services/messaging');
|
|||
const cls = require('../../services/cls');
|
||||
const path = require('path');
|
||||
const noteCacheService = require('../../services/note_cache');
|
||||
const log = require('../../services/log');
|
||||
|
||||
class ImportContext {
|
||||
constructor(importId) {
|
||||
|
@ -40,6 +41,14 @@ class ImportContext {
|
|||
noteId: noteId
|
||||
});
|
||||
}
|
||||
|
||||
// must remaing static
|
||||
async reportError(message) {
|
||||
await messagingService.sendMessageToAllClients({
|
||||
type: 'import-error',
|
||||
message: message
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function importToBranch(req) {
|
||||
|
@ -66,23 +75,28 @@ async function importToBranch(req) {
|
|||
|
||||
const importContext = new ImportContext(importId);
|
||||
|
||||
if (extension === '.tar') {
|
||||
note = await tarImportService.importTar(importContext, file.buffer, parentNote);
|
||||
try {
|
||||
if (extension === '.tar') {
|
||||
note = await tarImportService.importTar(importContext, file.buffer, parentNote);
|
||||
} else if (extension === '.opml') {
|
||||
note = await opmlImportService.importOpml(importContext, file.buffer, parentNote);
|
||||
} else if (extension === '.md') {
|
||||
note = await singleImportService.importMarkdown(importContext, file, parentNote);
|
||||
} else if (extension === '.html' || extension === '.htm') {
|
||||
note = await singleImportService.importHtml(importContext, file, parentNote);
|
||||
} else if (extension === '.enex') {
|
||||
note = await enexImportService.importEnex(importContext, file, parentNote);
|
||||
} else {
|
||||
return [400, `Unrecognized extension ${extension}, must be .tar or .opml`];
|
||||
}
|
||||
}
|
||||
else if (extension === '.opml') {
|
||||
note = await opmlImportService.importOpml(importContext, file.buffer, parentNote);
|
||||
}
|
||||
else if (extension === '.md') {
|
||||
note = await singleImportService.importMarkdown(importContext, file, parentNote);
|
||||
}
|
||||
else if (extension === '.html' || extension === '.htm') {
|
||||
note = await singleImportService.importHtml(importContext, file, parentNote);
|
||||
}
|
||||
else if (extension === '.enex') {
|
||||
note = await enexImportService.importEnex(importContext, file, parentNote);
|
||||
}
|
||||
else {
|
||||
return [400, `Unrecognized extension ${extension}, must be .tar or .opml`];
|
||||
catch (e) {
|
||||
const message = "Import failed with following error: '" + e.message + "'. More details might be in the logs.";
|
||||
importContext.reportError(message);
|
||||
|
||||
log.error(message + e.stack);
|
||||
|
||||
return [500, message];
|
||||
}
|
||||
|
||||
// import has deactivated note events so note cache is not updated
|
||||
|
|
|
@ -24,7 +24,7 @@ let lastSentCountTs = Date.now();
|
|||
*/
|
||||
async function importTar(importContext, fileBuffer, importRootNote) {
|
||||
importNoteCount = 0;
|
||||
|
||||
throw new Error("Hello");
|
||||
// maps from original noteId (in tar file) to newly generated noteId
|
||||
const noteIdMap = {};
|
||||
const attributes = [];
|
||||
|
|
Loading…
Reference in a new issue