Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
Merge remote-tracking branch 'origin/stable'
zadam8d0df6ddb9e8
diff --cc src/routes/api/notes.jsindex e4c706a653,98f4edf9b7..d3e4c50d9f--- a/src/routes/api/notes.js+++ b/src/routes/api/notes.js@@@ -15,10 -15,11 +15,11 @@@ function getNote(req)}if (note.isStringNote()) {- note.content = await note.getContent();+ note.content = note.getContent();- if (note.type === 'file') {- note.content = note.content.substr(0, 10000);+ if (note.type === 'file' && note.content.length > 10000) {+ note.content = note.content.substr(0, 10000)+ + `\r\n\r\n... and ${note.content.length - 10000} more characters.`;}}diff --cc src/services/notes.jsindex b414e9b8ab,ed0a024972..e584068d5e--- a/src/services/notes.js+++ b/src/services/notes.js@@@ -279,18 -279,15 +279,15 @@@ const downloadImagePromises = {}function replaceUrl(content, url, imageNote) {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}[\"']`, "ig"), ` src="api/images/${imageNote.noteId}/${imageNote.title}"`);}-async function downloadImages(noteId, content) {+function downloadImages(noteId, content) {- const re = /<img[^>]*?\ssrc=['"]([^'">]+)['"]/ig;- let match;-- const origContent = content;-- while (match = re.exec(origContent)) {- const url = match[1];+ const imageRe = /<img[^>]*?\ssrc=['"]([^'">]+)['"]/ig;+ let imageMatch;+ while (imageMatch = imageRe.exec(content)) {+ const url = imageMatch[1];const inlineImageMatch = /^data:image\/[a-z]+;base64,/.exec(url);if (inlineImageMatch) {@@@ -298,11 -295,11 +295,11 @@@const imageBuffer = Buffer.from(imageBase64, 'base64');const imageService = require('../services/image');- const {note} = await imageService.saveImage(noteId, imageBuffer, "inline image", true);+ const {note} = imageService.saveImage(noteId, imageBuffer, "inline image", true);- content = content.substr(0, match.index)+ content = content.substr(0, imageMatch.index)+ `<img src="api/images/${note.noteId}/${note.title}"`- + content.substr(match.index + match[0].length);+ + content.substr(imageMatch.index + imageMatch[0].length);}else if (!url.includes('api/images/')// this is an exception for the web clipper's "imageId"diff --cc src/services/request.jsindex 6e982cf927,32ed7230e5..1b9b3cd2b6--- a/src/services/request.js+++ b/src/services/request.js@@@ -83,7 -83,8 +83,8 @@@ function exec(opts)});}-async function getImage(imageUrl) {- const proxyConf = await syncOptions.getSyncProxy();+function getImage(imageUrl) {++ const proxyConf = syncOptions.getSyncProxy();const opts = {method: 'GET',url: imageUrl,diff --cc src/services/utils.jsindex 1f0cf52aab,db75ce32f0..aecb939996--- a/src/services/utils.js+++ b/src/services/utils.js@@@ -155,11 -159,14 +155,15 @@@ function getContentDisposition(filenamereturn `file; filename="${sanitizedFilename}"; filename*=UTF-8''${sanitizedFilename}`;}- const STRING_MIME_TYPES = ["application/x-javascript", "image/svg+xml"];+ const STRING_MIME_TYPES = [+ "application/javascript",+ "application/x-javascript",+ "image/svg+xml"+ ];function isStringNote(type, mime) {- return ["text", "code", "relation-map", "search"].includes(type)+ // render and book are string note in the sense that they are expected to contain empty string+ return ["text", "code", "relation-map", "search", "render", "book"].includes(type)|| mime.startsWith('text/')|| STRING_MIME_TYPES.includes(mime);}