Skip to content

Commit

Permalink
Merge pull request #645 from TriliumNext/renovate/image-type-5.x
Browse files Browse the repository at this point in the history
fix(deps): update dependency image-type to v5
  • Loading branch information
eliandoran authored Dec 10, 2024
2 parents abd5238 + e0e98e2 commit 289e33f
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 15 deletions.
80 changes: 70 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"i18next": "24.0.5",
"i18next-fs-backend": "2.6.0",
"i18next-http-backend": "3.0.1",
"image-type": "4.1.0",
"image-type": "5.2.0",
"ini": "5.0.0",
"is-animated": "2.0.2",
"is-svg": "5.1.0",
Expand Down
8 changes: 4 additions & 4 deletions src/services/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import htmlSanitizer from "./html_sanitizer.js";

async function processImage(uploadBuffer: Buffer, originalName: string, shrinkImageSwitch: boolean) {
const compressImages = optionService.getOptionBool("compressImages");
const origImageFormat = getImageType(uploadBuffer);
const origImageFormat = await getImageType(uploadBuffer);

if (!origImageFormat || !["jpg", "png"].includes(origImageFormat.ext)) {
shrinkImageSwitch = false;
Expand All @@ -30,7 +30,7 @@ async function processImage(uploadBuffer: Buffer, originalName: string, shrinkIm

if (compressImages && shrinkImageSwitch) {
finalImageBuffer = await shrinkImage(uploadBuffer, originalName);
imageFormat = getImageType(finalImageBuffer);
imageFormat = await getImageType(finalImageBuffer);
} else {
finalImageBuffer = uploadBuffer;
imageFormat = origImageFormat || {
Expand All @@ -44,12 +44,12 @@ async function processImage(uploadBuffer: Buffer, originalName: string, shrinkIm
};
}

function getImageType(buffer: Buffer) {
async function getImageType(buffer: Buffer) {
if (isSvg(buffer.toString())) {
return { ext: 'svg' }
}
else {
return imageType(buffer) || { ext: "jpg" }; // optimistic JPG default
return await imageType(buffer) || { ext: "jpg" }; // optimistic JPG default
}
}

Expand Down

0 comments on commit 289e33f

Please sign in to comment.