mirror of
https://github.com/zadam/trilium.git
synced 2025-02-01 12:00:17 +08:00
fix importing unknown image types such as .DWG, closes #2628
This commit is contained in:
parent
40598d2663
commit
59e8720866
1 changed files with 15 additions and 5 deletions
|
@ -17,8 +17,7 @@ async function processImage(uploadBuffer, originalName, shrinkImageSwitch) {
|
|||
const compressImages = optionService.getOptionBool("compressImages");
|
||||
const origImageFormat = getImageType(uploadBuffer);
|
||||
|
||||
if (origImageFormat && ["webp", "svg", "gif"].includes(origImageFormat.ext)) {
|
||||
// JIMP does not support webp at the moment: https://github.com/oliver-moran/jimp/issues/144
|
||||
if (!origImageFormat || !["jpg", "png"].includes(origImageFormat.ext)) {
|
||||
shrinkImageSwitch = false;
|
||||
}
|
||||
else if (isAnimated(uploadBuffer)) {
|
||||
|
@ -26,9 +25,18 @@ async function processImage(uploadBuffer, originalName, shrinkImageSwitch) {
|
|||
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 {
|
||||
buffer: finalImageBuffer,
|
||||
|
@ -43,7 +51,9 @@ function getImageType(buffer) {
|
|||
}
|
||||
}
|
||||
else {
|
||||
return imageType(buffer) || "jpg"; // optimistic JPG default
|
||||
return imageType(buffer) || {
|
||||
ext: "jpg"
|
||||
}; // optimistic JPG default
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue