debugging info for image shrinking

This commit is contained in:
zadam 2019-03-03 20:41:03 +01:00
parent e628c30c89
commit 95d8f07458
3 changed files with 18 additions and 35 deletions

45
package-lock.json generated
View file

@ -4935,9 +4935,9 @@
}
},
"get-port": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/get-port/-/get-port-4.1.0.tgz",
"integrity": "sha512-4/fqAYrzrzOiqDrdeZRKXGdTGgbkfTEumGlNQPeP6Jy8w0PzN9mzeNQ3XgHaTNie8pQ3hOUkrwlZt2Fzk5H9mA=="
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/get-port/-/get-port-4.2.0.tgz",
"integrity": "sha512-/b3jarXkH8KJoOMQc3uVGHASwGLPq3gSFJ7tgJm2diza+bydJPTGOibin2steecKeOylE8oY2JERlVWkAJO6yw=="
},
"get-proxy": {
"version": "1.1.0",
@ -11047,11 +11047,11 @@
}
},
"tar-stream": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-2.0.0.tgz",
"integrity": "sha512-n2vtsWshZOVr/SY4KtslPoUlyNh06I2SGgAOCZmquCEjlbV/LjY2CY80rDtdQRHFOYXNlgBDo6Fr3ww2CWPOtA==",
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-2.0.1.tgz",
"integrity": "sha512-I6OJF7wE62BC6zNPdHDtseK0D0187PBjbKSLYY4ffvVkBM6tyBn2O9plDvVM2229/mozfEL/X3++qSvYYQE2xw==",
"requires": {
"bl": "^2.2.0",
"bl": "^3.0.0",
"end-of-stream": "^1.4.1",
"fs-constants": "^1.0.0",
"inherits": "^2.0.3",
@ -11059,34 +11059,17 @@
},
"dependencies": {
"bl": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/bl/-/bl-2.2.0.tgz",
"integrity": "sha512-wbgvOpqopSr7uq6fJrLH8EsvYMJf9gzfo2jCsL2eTy75qXPukA4pCgHamOQkZtY5vmfVtjB+P3LNlMHW5CEZXA==",
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/bl/-/bl-3.0.0.tgz",
"integrity": "sha512-EUAyP5UHU5hxF8BPT0LKW8gjYLhq1DQIcneOX/pL/m2Alo+OYDQAJlHq+yseMP50Os2nHXOSic6Ss3vSQeyf4A==",
"requires": {
"readable-stream": "^2.3.5",
"safe-buffer": "^5.1.1"
},
"dependencies": {
"readable-stream": {
"version": "2.3.6",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz",
"integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==",
"requires": {
"core-util-is": "~1.0.0",
"inherits": "~2.0.3",
"isarray": "~1.0.0",
"process-nextick-args": "~2.0.0",
"safe-buffer": "~5.1.1",
"string_decoder": "~1.1.1",
"util-deprecate": "~1.0.1"
}
}
"readable-stream": "^3.0.1"
}
},
"readable-stream": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.1.1.tgz",
"integrity": "sha512-DkN66hPyqDhnIQ6Jcsvx9bFjhw214O4poMBcIMgPVpQvNy9a0e0Uhg5SqySyDKAmUlwt8LonTBz1ezOnM8pUdA==",
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.2.0.tgz",
"integrity": "sha512-RV20kLjdmpZuTF1INEb9IA3L68Nmi+Ri7ppZqo78wj//Pn62fCoJyV9zalccNzDD/OuJpMG4f+pfMl8+L6QdGw==",
"requires": {
"inherits": "^2.0.3",
"string_decoder": "^1.1.1",

View file

@ -37,7 +37,7 @@
"express-session": "1.15.6",
"file-type": "10.8.0",
"fs-extra": "7.0.1",
"get-port": "4.1.0",
"get-port": "4.2.0",
"helmet": "3.15.1",
"html": "1.0.0",
"image-type": "3.0.0",

View file

@ -13,7 +13,7 @@ const imageType = require('image-type');
const sanitizeFilename = require('sanitize-filename');
async function saveImage(buffer, originalName, parentNoteId, shrinkImageSwitch) {
const finalImageBuffer = shrinkImageSwitch ? await shrinkImage(buffer) : buffer;
const finalImageBuffer = shrinkImageSwitch ? await shrinkImage(buffer, originalName) : buffer;
const imageFormat = imageType(finalImageBuffer);
@ -41,14 +41,14 @@ async function saveImage(buffer, originalName, parentNoteId, shrinkImageSwitch)
};
}
async function shrinkImage(buffer) {
async function shrinkImage(buffer, originalName) {
const resizedImage = await resize(buffer);
let finalImageBuffer;
try {
finalImageBuffer = await optimize(resizedImage);
} catch (e) {
log.error(e.message + e.stack);
log.error("Failed to optimize image '" + originalName + "\nStack: " + e.stack);
finalImageBuffer = resizedImage;
}
return finalImageBuffer;