mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-11-04 15:11:31 +08:00 
			
		
		
		
	fix importing unknown image types such as .DWG, closes #2628
This commit is contained in:
		
							parent
							
								
									40598d2663
								
							
						
					
					
						commit
						59e8720866
					
				@ -17,8 +17,7 @@ async function processImage(uploadBuffer, originalName, shrinkImageSwitch) {
 | 
				
			|||||||
    const compressImages = optionService.getOptionBool("compressImages");
 | 
					    const compressImages = optionService.getOptionBool("compressImages");
 | 
				
			||||||
    const origImageFormat = getImageType(uploadBuffer);
 | 
					    const origImageFormat = getImageType(uploadBuffer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (origImageFormat && ["webp", "svg", "gif"].includes(origImageFormat.ext)) {
 | 
					    if (!origImageFormat || !["jpg", "png"].includes(origImageFormat.ext)) {
 | 
				
			||||||
        // JIMP does not support webp at the moment: https://github.com/oliver-moran/jimp/issues/144
 | 
					 | 
				
			||||||
        shrinkImageSwitch = false;
 | 
					        shrinkImageSwitch = false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else if (isAnimated(uploadBuffer)) {
 | 
					    else if (isAnimated(uploadBuffer)) {
 | 
				
			||||||
@ -26,9 +25,18 @@ async function processImage(uploadBuffer, originalName, shrinkImageSwitch) {
 | 
				
			|||||||
        shrinkImageSwitch = false;
 | 
					        shrinkImageSwitch = false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const finalImageBuffer = (compressImages && shrinkImageSwitch) ? await shrinkImage(uploadBuffer, originalName) : uploadBuffer;
 | 
					    let finalImageBuffer;
 | 
				
			||||||
 | 
					    let imageFormat;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const imageFormat = getImageType(finalImageBuffer);
 | 
					    if (compressImages && shrinkImageSwitch) {
 | 
				
			||||||
 | 
					        finalImageBuffer = await shrinkImage(uploadBuffer, originalName);
 | 
				
			||||||
 | 
					        imageFormat = getImageType(finalImageBuffer);
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        finalImageBuffer = uploadBuffer;
 | 
				
			||||||
 | 
					        imageFormat = origImageFormat || {
 | 
				
			||||||
 | 
					            ext: 'dat'
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return {
 | 
					    return {
 | 
				
			||||||
        buffer: finalImageBuffer,
 | 
					        buffer: finalImageBuffer,
 | 
				
			||||||
@ -43,7 +51,9 @@ function getImageType(buffer) {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else {
 | 
					    else {
 | 
				
			||||||
        return imageType(buffer) || "jpg"; // optimistic JPG default
 | 
					        return imageType(buffer) || {
 | 
				
			||||||
 | 
					            ext: "jpg"
 | 
				
			||||||
 | 
					        }; // optimistic JPG default
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user