From 3d324b954d89bf3366dcabfec36fd4d38d8174cd Mon Sep 17 00:00:00 2001 From: zadam Date: Wed, 15 Jul 2020 22:36:27 +0200 Subject: [PATCH 1/2] fix checking affected notes when modified attribute's owning note is not loaded into cache, #803 --- src/public/app/entities/attribute.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/public/app/entities/attribute.js b/src/public/app/entities/attribute.js index 91b8044da..f6471f355 100644 --- a/src/public/app/entities/attribute.js +++ b/src/public/app/entities/attribute.js @@ -52,7 +52,17 @@ class Attribute { * 3. attribute is owned by some note's ancestor and is inheritable */ isAffecting(affectedNote) { + if (!affectedNote) { + return false; + } + const attrNote = this.getNote(); + + if (!attrNote) { + // the note (owner of the attribute) is not even loaded into the cache so it should not affect anything else + return false; + } + const owningNotes = [affectedNote, ...affectedNote.getTemplateNotes()]; for (const owningNote of owningNotes) { From 099e90ed64b893b2da36da89e55837b13c614070 Mon Sep 17 00:00:00 2001 From: zadam Date: Sun, 26 Jul 2020 22:58:22 +0200 Subject: [PATCH 2/2] fix extracting base64 inline images from HTML, fixes #1159 --- src/public/app/services/tree_cache.js | 6 ++++++ src/services/notes.js | 25 +++++++++++++++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/public/app/services/tree_cache.js b/src/public/app/services/tree_cache.js index 8461a1f58..fe9ccc301 100644 --- a/src/public/app/services/tree_cache.js +++ b/src/public/app/services/tree_cache.js @@ -273,6 +273,12 @@ class TreeCache { async getBranchId(parentNoteId, childNoteId) { const child = await this.getNote(childNoteId); + if (!child) { + console.error(`Could not find branchId for parent=${parentNoteId}, child=${childNoteId} since child does not exist`); + + return null; + } + return child.parentToBranch[parentNoteId]; } diff --git a/src/services/notes.js b/src/services/notes.js index be11fd196..fd341214a 100644 --- a/src/services/notes.js +++ b/src/services/notes.js @@ -277,9 +277,15 @@ async function downloadImage(noteId, imageUrl) { const downloadImagePromises = {}; function replaceUrl(content, url, imageNote) { - const quotedUrl = utils.quoteRegex(url); + if (url.length > 2000) { + // for very large inline base64 images which fail on regex max size + return content.replace(url, `api/images/${imageNote.noteId}/${imageNote.title}`); + } + else { + const quotedUrl = utils.quoteRegex(url); - return content.replace(new RegExp(`\\s+src=[\"']${quotedUrl}[\"']`, "g"), ` src="api/images/${imageNote.noteId}/${imageNote.title}"`); + return content.replace(new RegExp(`\\s+src=[\"']${quotedUrl}[\"']`, "g"), ` src="api/images/${imageNote.noteId}/${imageNote.title}"`); + } } async function downloadImages(noteId, content) { @@ -291,8 +297,19 @@ async function downloadImages(noteId, content) { while (match = re.exec(origContent)) { const url = match[1]; - if (!url.includes('api/images/') - // this is and exception for the web clipper's "imageId" + const inlineImageMatch = /^data:image\/[a-z]+;base64,/.exec(url); + + if (inlineImageMatch) { + const imageBase64 = url.substr(inlineImageMatch[0].length); + const imageBuffer = Buffer.from(imageBase64, 'base64'); + + const imageService = require('../services/image'); + const {note} = await imageService.saveImage(noteId, imageBuffer, "inline image", true); + + content = replaceUrl(content, url, note); + } + else if (!url.includes('api/images/') + // this is an exception for the web clipper's "imageId" && (url.length !== 20 || url.toLowerCase().startsWith('http'))) { if (url in imageUrlToNoteIdMapping) {