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
fix noproxy handling for image downloading
zadam782127dd91a8
diff --git a/src/services/notes.js b/src/services/notes.jsindex 646d6bc5f8..ed0a024972 100644--- a/src/services/notes.js+++ b/src/services/notes.js@@ -279,18 +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) {- 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) {@@ -300,9 +297,9 @@ async function downloadImages(noteId, content) {const imageService = require('../services/image');const {note} = await 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"@@ -316,7 +313,6 @@ async function downloadImages(noteId, content) {}else {content = replaceUrl(content, url, imageNote);-continue;}}@@ -328,7 +324,6 @@ async function downloadImages(noteId, content) {imageUrlToNoteIdMapping[url] = existingImage.noteId;content = replaceUrl(content, url, existingImage);-continue;}diff --git a/src/services/request.js b/src/services/request.jsindex 41d31f7742..32ed7230e5 100644--- a/src/services/request.js+++ b/src/services/request.js@@ -84,10 +84,11 @@ function exec(opts) {}async function getImage(imageUrl) {+ const proxyConf = await syncOptions.getSyncProxy();const opts = {method: 'GET',url: imageUrl,- proxy: await syncOptions.getSyncProxy()+ proxy: proxyConf !== "noproxy" ? proxyConf : null};const client = getClient(opts);