Skip to content

Build your personal knowledge base with Trilium Notes

fixes for web clipper

zadam3bbb213f822a
diff --git a/package.json b/package.json
index 4a2b74e9c7..d2b2f0d4da 100644
--- a/package.json
+++ b/package.json
@@ -77,7 +77,7 @@
"yazl": "^2.5.1"
},
"devDependencies": {
- "electron": "9.0.0-beta.12",
+ "electron": "9.0.0-beta.13",
"electron-builder": "22.4.1",
"electron-packager": "14.2.1",
"electron-rebuild": "1.10.1",
diff --git a/src/public/javascripts/widgets/note_tree.js b/src/public/javascripts/widgets/note_tree.js
index 9c937c8aad..3273e51747 100644
--- a/src/public/javascripts/widgets/note_tree.js
+++ b/src/public/javascripts/widgets/note_tree.js
@@ -559,7 +559,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
if (activeNotePath) {
let node = await this.expandToNote(activeNotePath);
- if (node.data.noteId !== activeNoteId) {
+ if (node && node.data.noteId !== activeNoteId) {
// if the active note has been moved elsewhere then it won't be found by the path
// so we switch to the alternative of trying to find it by noteId
const notesById = this.getNodesByNoteId(activeNoteId);
diff --git a/src/routes/api/clipper.js b/src/routes/api/clipper.js
index e02fbfaaba..986268c7ae 100644
--- a/src/routes/api/clipper.js
+++ b/src/routes/api/clipper.js
@@ -114,7 +114,7 @@ async function addImagesToNote(images, note, content) {
console.log(`Replacing ${imageId} with ${url}`);
- rewrittenContent = rewrittenContent.replace(imageId, url);
+ rewrittenContent = utils.replaceAll(rewrittenContent, imageId, url);
}
}
diff --git a/src/services/notes.js b/src/services/notes.js
index 54fe87535d..49de14d59b 100644
--- a/src/services/notes.js
+++ b/src/services/notes.js
@@ -282,7 +282,7 @@ async function downloadImage(noteId, imageUrl) {
log.info(`Download of ${imageUrl} succeeded and was saved as image note ${note.noteId}`);
}
catch (e) {
- log.error(`Downoad of ${imageUrl} for note ${noteId} failed with error: ${e.message} ${e.stack}`);
+ log.error(`Download of ${imageUrl} for note ${noteId} failed with error: ${e.message} ${e.stack}`);
}
}
@@ -296,13 +296,17 @@ function replaceUrl(content, url, imageNote) {
}
async function downloadImages(noteId, content) {
- const re = /<img.*?\ssrc=['"]([^'">]+)['"]/ig;
+ const re = /<img[^>]*?\ssrc=['"]([^'">]+)['"]/ig;
let match;
- while (match = re.exec(content)) {
- const url = match[1];
+ const origContent = content;
+
+ while (match = re.exec(origContent)) {
+ const url = match[1].toLowerCase();
- if (!url.startsWith('api/images/')) {
+ if (!url.startsWith('api/images/')
+ // this is and exception for the web clipper's "imageId"
+ && (url.length !== 20 || url.startsWith('http'))) {
if (url in downloadImagePromises) {
// download is already in progress
continue;
@@ -386,12 +390,19 @@ async function saveLinks(note, content) {
const foundLinks = [];
if (note.type === 'text') {
+ console.time("LINKS");
+
content = findImageLinks(content, foundLinks);
content = findInternalLinks(content, foundLinks);
content = findExternalLinks(content, foundLinks);
content = findIncludeNoteLinks(content, foundLinks);
+ console.timeEnd("LINKS");
+ console.time("IMAGES");
+
content = await downloadImages(note.noteId, content);
+
+ console.timeEnd("IMAGES");
}
else if (note.type === 'relation-map') {
findRelationMapLinks(content, foundLinks);
diff --git a/src/services/utils.js b/src/services/utils.js
index 4a7a5bd321..57af4218e8 100644
--- a/src/services/utils.js
+++ b/src/services/utils.js
@@ -166,6 +166,12 @@ function isStringNote(type, mime) {
|| STRING_MIME_TYPES.includes(mime);
}
+function replaceAll(string, replaceWhat, replaceWith) {
+ const escapedWhat = replaceWhat.replace(/([\/,!\\^${}\[\]().*+?|<>\-&])/g, "\\$&");
+
+ return string.replace(new RegExp(escapedWhat, "g"), replaceWith);
+}
+
module.exports = {
randomSecureToken,
randomString,
@@ -191,5 +197,6 @@ module.exports = {
crash,
sanitizeFilenameForHeader,
getContentDisposition,
- isStringNote
+ isStringNote,
+ replaceAll
};
\ No newline at end of file