yet another refactoring of working with note's payload/content

This commit is contained in:
zadam
2019-03-26 22:24:04 +01:00
parent 4bdcf32475
commit 29c60581a6
31 changed files with 126 additions and 239 deletions

View File

@@ -223,7 +223,7 @@ async function importEnex(importContext, file, parentNote) {
importContext.increaseProgressCount();
const noteContent = await noteEntity.getNoteContent();
let noteContent = await noteEntity.getContent();
for (const resource of resources) {
const hash = utils.md5(resource.content);
@@ -248,7 +248,7 @@ async function importEnex(importContext, file, parentNote) {
const resourceLink = `<a href="#root/${resourceNote.noteId}">${utils.escapeHtml(resource.title)}</a>`;
noteContent.content = noteContent.content.replace(mediaRegex, resourceLink);
noteContent = noteContent.replace(mediaRegex, resourceLink);
};
if (["image/jpeg", "image/png", "image/gif"].includes(resource.mime)) {
@@ -259,12 +259,12 @@ async function importEnex(importContext, file, parentNote) {
const imageLink = `<img src="${url}">`;
noteContent.content = noteContent.content.replace(mediaRegex, imageLink);
noteContent = noteContent.replace(mediaRegex, imageLink);
if (!noteContent.content.includes(imageLink)) {
if (!noteContent.includes(imageLink)) {
// if there wasn't any match for the reference, we'll add the image anyway
// otherwise image would be removed since no note would include it
noteContent.content += imageLink;
noteContent += imageLink;
}
} catch (e) {
log.error("error when saving image from ENEX file: " + e);
@@ -276,7 +276,7 @@ async function importEnex(importContext, file, parentNote) {
}
// save updated content with links to files/images
await noteContent.save();
await noteEntity.setContent(noteContent);
}
saxStream.on("closetag", async tag => {

View File

@@ -259,10 +259,7 @@ async function importTar(importContext, fileBuffer, importRootNote) {
let note = await repository.getNote(noteId);
if (note) {
const noteContent = await note.getNoteContent();
noteContent.content = content;
await noteContent.save();
await note.setContent(content);
}
else {
const noteTitle = getNoteTitle(filePath, noteMeta);