mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
fixes for web clipper
This commit is contained in:
parent
bab657e43d
commit
3bbb213f82
@ -77,7 +77,7 @@
|
|||||||
"yazl": "^2.5.1"
|
"yazl": "^2.5.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"electron": "9.0.0-beta.12",
|
"electron": "9.0.0-beta.13",
|
||||||
"electron-builder": "22.4.1",
|
"electron-builder": "22.4.1",
|
||||||
"electron-packager": "14.2.1",
|
"electron-packager": "14.2.1",
|
||||||
"electron-rebuild": "1.10.1",
|
"electron-rebuild": "1.10.1",
|
||||||
|
@ -559,7 +559,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
|
|||||||
if (activeNotePath) {
|
if (activeNotePath) {
|
||||||
let node = await this.expandToNote(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
|
// 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
|
// so we switch to the alternative of trying to find it by noteId
|
||||||
const notesById = this.getNodesByNoteId(activeNoteId);
|
const notesById = this.getNodesByNoteId(activeNoteId);
|
||||||
|
@ -114,7 +114,7 @@ async function addImagesToNote(images, note, content) {
|
|||||||
|
|
||||||
console.log(`Replacing ${imageId} with ${url}`);
|
console.log(`Replacing ${imageId} with ${url}`);
|
||||||
|
|
||||||
rewrittenContent = rewrittenContent.replace(imageId, url);
|
rewrittenContent = utils.replaceAll(rewrittenContent, imageId, url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,7 +282,7 @@ async function downloadImage(noteId, imageUrl) {
|
|||||||
log.info(`Download of ${imageUrl} succeeded and was saved as image note ${note.noteId}`);
|
log.info(`Download of ${imageUrl} succeeded and was saved as image note ${note.noteId}`);
|
||||||
}
|
}
|
||||||
catch (e) {
|
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) {
|
async function downloadImages(noteId, content) {
|
||||||
const re = /<img.*?\ssrc=['"]([^'">]+)['"]/ig;
|
const re = /<img[^>]*?\ssrc=['"]([^'">]+)['"]/ig;
|
||||||
let match;
|
let match;
|
||||||
|
|
||||||
while (match = re.exec(content)) {
|
const origContent = content;
|
||||||
const url = match[1];
|
|
||||||
|
|
||||||
if (!url.startsWith('api/images/')) {
|
while (match = re.exec(origContent)) {
|
||||||
|
const url = match[1].toLowerCase();
|
||||||
|
|
||||||
|
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) {
|
if (url in downloadImagePromises) {
|
||||||
// download is already in progress
|
// download is already in progress
|
||||||
continue;
|
continue;
|
||||||
@ -386,12 +390,19 @@ async function saveLinks(note, content) {
|
|||||||
const foundLinks = [];
|
const foundLinks = [];
|
||||||
|
|
||||||
if (note.type === 'text') {
|
if (note.type === 'text') {
|
||||||
|
console.time("LINKS");
|
||||||
|
|
||||||
content = findImageLinks(content, foundLinks);
|
content = findImageLinks(content, foundLinks);
|
||||||
content = findInternalLinks(content, foundLinks);
|
content = findInternalLinks(content, foundLinks);
|
||||||
content = findExternalLinks(content, foundLinks);
|
content = findExternalLinks(content, foundLinks);
|
||||||
content = findIncludeNoteLinks(content, foundLinks);
|
content = findIncludeNoteLinks(content, foundLinks);
|
||||||
|
|
||||||
|
console.timeEnd("LINKS");
|
||||||
|
console.time("IMAGES");
|
||||||
|
|
||||||
content = await downloadImages(note.noteId, content);
|
content = await downloadImages(note.noteId, content);
|
||||||
|
|
||||||
|
console.timeEnd("IMAGES");
|
||||||
}
|
}
|
||||||
else if (note.type === 'relation-map') {
|
else if (note.type === 'relation-map') {
|
||||||
findRelationMapLinks(content, foundLinks);
|
findRelationMapLinks(content, foundLinks);
|
||||||
|
@ -166,6 +166,12 @@ function isStringNote(type, mime) {
|
|||||||
|| STRING_MIME_TYPES.includes(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 = {
|
module.exports = {
|
||||||
randomSecureToken,
|
randomSecureToken,
|
||||||
randomString,
|
randomString,
|
||||||
@ -191,5 +197,6 @@ module.exports = {
|
|||||||
crash,
|
crash,
|
||||||
sanitizeFilenameForHeader,
|
sanitizeFilenameForHeader,
|
||||||
getContentDisposition,
|
getContentDisposition,
|
||||||
isStringNote
|
isStringNote,
|
||||||
|
replaceAll
|
||||||
};
|
};
|
Loading…
x
Reference in New Issue
Block a user