From d57a303251f029d68aee36e2f9a0771bc1a2b41b Mon Sep 17 00:00:00 2001 From: zadam Date: Wed, 16 Sep 2020 20:32:20 +0200 Subject: [PATCH] fix in ENEX import --- src/routes/api/clipper.js | 11 +++++++---- src/services/import/enex.js | 4 ++-- src/services/note_cache/similarity.js | 6 +++--- src/services/notes.js | 2 ++ 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/routes/api/clipper.js b/src/routes/api/clipper.js index a58d03ce9..b7d5663de 100644 --- a/src/routes/api/clipper.js +++ b/src/routes/api/clipper.js @@ -53,7 +53,7 @@ function addClipping(req) { clippingNote.setLabel('pageUrl', pageUrl); } - const rewrittenContent = addImagesToNote(images, clippingNote, content); + const rewrittenContent = processContent(images, clippingNote, content); const existingContent = clippingNote.getContent(); @@ -85,7 +85,7 @@ function createNote(req) { note.setLabel('pageUrl', pageUrl); } - const rewrittenContent = addImagesToNote(images, note, content); + const rewrittenContent = processContent(images, note, content); note.setContent(rewrittenContent); @@ -94,8 +94,11 @@ function createNote(req) { }; } -function addImagesToNote(images, note, content) { - let rewrittenContent = content; +function processContent(images, note, content) { + // H1 is not supported so convert it to H2 + let rewrittenContent = content + .replace(/

{ - const resourceNote = (noteService.createNewNote({ + const resourceNote = noteService.createNewNote({ parentNoteId: noteEntity.noteId, title: resource.title, content: resource.content, type: 'file', mime: resource.mime, isProtected: parentNote.isProtected && protectedSessionService.isProtectedSessionAvailable(), - })).note; + }).note; for (const attr of resource.attributes) { noteEntity.addAttribute(attr.type, attr.name, attr.value); diff --git a/src/services/note_cache/similarity.js b/src/services/note_cache/similarity.js index 3bc47890d..8be5f9dda 100644 --- a/src/services/note_cache/similarity.js +++ b/src/services/note_cache/similarity.js @@ -11,9 +11,9 @@ const IGNORED_ATTR_NAMES = [ function filterLabelValue(value) { return value - .replace(/https?:\/\//i, "") - .replace(/www\./i, "") - .replace(/(\.net|\.com|\.org|\.info|\.edu)/i, ""); + .replace(/https?:\/\//ig, "") + .replace(/www\./ig, "") + .replace(/(\.net|\.com|\.org|\.info|\.edu)/ig, ""); } /** diff --git a/src/services/notes.js b/src/services/notes.js index 745a87542..14f0eefef 100644 --- a/src/services/notes.js +++ b/src/services/notes.js @@ -55,6 +55,8 @@ function deriveMime(type, mime) { mime = 'application/json'; } else if (['render', 'book'].includes(type)) { mime = ''; + } else { + mime = 'application/octet-stream'; } return mime;