mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 13:01:31 +08:00 
			
		
		
		
	fix extracting base64 inline images from HTML, fixes #1159
This commit is contained in:
		
							parent
							
								
									099e90ed64
								
							
						
					
					
						commit
						5f4a84d967
					
				| @ -277,16 +277,10 @@ async function downloadImage(noteId, imageUrl) { | |||||||
| const downloadImagePromises = {}; | const downloadImagePromises = {}; | ||||||
| 
 | 
 | ||||||
| function replaceUrl(content, url, imageNote) { | function replaceUrl(content, url, imageNote) { | ||||||
|     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); |     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}"`); | ||||||
| } | } | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| async function downloadImages(noteId, content) { | async function downloadImages(noteId, content) { | ||||||
|     const re = /<img[^>]*?\ssrc=['"]([^'">]+)['"]/ig; |     const re = /<img[^>]*?\ssrc=['"]([^'">]+)['"]/ig; | ||||||
| @ -306,7 +300,9 @@ async function downloadImages(noteId, content) { | |||||||
|             const imageService = require('../services/image'); |             const imageService = require('../services/image'); | ||||||
|             const {note} = await imageService.saveImage(noteId, imageBuffer, "inline image", true); |             const {note} = await imageService.saveImage(noteId, imageBuffer, "inline image", true); | ||||||
| 
 | 
 | ||||||
|             content = replaceUrl(content, url, note); |             content = content.substr(0, match.index) | ||||||
|  |                 + `<img src="api/images/${note.noteId}/${note.title}"` | ||||||
|  |                 + content.substr(match.index + match[0].length); | ||||||
|         } |         } | ||||||
|         else if (!url.includes('api/images/') |         else if (!url.includes('api/images/') | ||||||
|             // this is an exception for the web clipper's "imageId"
 |             // this is an exception for the web clipper's "imageId"
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 zadam
						zadam