mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 18:36:30 +01:00 
			
		
		
		
	Merge remote-tracking branch 'origin/stable'
This commit is contained in:
		| @@ -54,6 +54,12 @@ class Attribute { | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         const attrNote = this.getNote(); |         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()]; |         const owningNotes = [affectedNote, ...affectedNote.getTemplateNotes()]; | ||||||
|  |  | ||||||
|         for (const owningNote of owningNotes) { |         for (const owningNote of owningNotes) { | ||||||
|   | |||||||
| @@ -273,6 +273,12 @@ class TreeCache { | |||||||
|     async getBranchId(parentNoteId, childNoteId) { |     async getBranchId(parentNoteId, childNoteId) { | ||||||
|         const child = await this.getNote(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]; |         return child.parentToBranch[parentNoteId]; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -277,9 +277,15 @@ async function downloadImage(noteId, imageUrl) { | |||||||
| const downloadImagePromises = {}; | const downloadImagePromises = {}; | ||||||
|  |  | ||||||
| function replaceUrl(content, url, imageNote) { | 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}"`); | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| function downloadImages(noteId, content) { | function downloadImages(noteId, content) { | ||||||
| @@ -291,8 +297,19 @@ function downloadImages(noteId, content) { | |||||||
|     while (match = re.exec(origContent)) { |     while (match = re.exec(origContent)) { | ||||||
|         const url = match[1]; |         const url = match[1]; | ||||||
|  |  | ||||||
|         if (!url.includes('api/images/') |         const inlineImageMatch = /^data:image\/[a-z]+;base64,/.exec(url); | ||||||
|             // this is and exception for the web clipper's "imageId" |  | ||||||
|  |         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'))) { |             && (url.length !== 20 || url.toLowerCase().startsWith('http'))) { | ||||||
|  |  | ||||||
|             if (url in imageUrlToNoteIdMapping) { |             if (url in imageUrlToNoteIdMapping) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user