mirror of
https://github.com/zadam/trilium.git
synced 2025-11-17 18:50:41 +01:00
yet another refactoring of working with note's payload/content
This commit is contained in:
@@ -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 => {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user