|
|
|
|
@ -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);
|
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
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 {
|
|
|
|
|
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
|
|
|
|
|
|