From 262a4fa3c7bac97b49acd1aaa59330954cc0cb93 Mon Sep 17 00:00:00 2001 From: zadam Date: Sun, 28 Jun 2020 22:36:42 +0200 Subject: [PATCH] removed image minification using imagemin because of constant platform related issues --- package-lock.json | 204 ++++++++++++++++++++++-------------------- package.json | 6 +- src/services/image.js | 37 +------- 3 files changed, 112 insertions(+), 135 deletions(-) diff --git a/package-lock.json b/package-lock.json index ceb04b3a5..47a9085e1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -661,6 +661,16 @@ "integrity": "sha512-FA/BWv8t8ZWJ+gEOnLLd8ygxH/2UFbAvgEonyfN6yWGLKc7zVjbpl2Y4CTjid9h2RfgPP6SEt6uHwEOply00yw==", "dev": true }, + "@types/yauzl": { + "version": "2.9.1", + "resolved": "https://registry.npmjs.org/@types/yauzl/-/yauzl-2.9.1.tgz", + "integrity": "sha512-A1b8SU4D10uoPjwb0lnHmmu8wZhR9d+9o2PKBQT2jU5YPTKsxac6M2qGAdY7VcL+dHHhARVUDmeg0rOrcd9EjA==", + "dev": true, + "optional": true, + "requires": { + "@types/node": "*" + } + }, "@webassemblyjs/ast": { "version": "1.9.0", "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.9.0.tgz", @@ -1354,6 +1364,7 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/asar/-/asar-2.0.1.tgz", "integrity": "sha512-Vo9yTuUtyFahkVMFaI6uMuX6N7k5DWa6a/8+7ov0/f8Lq9TVR0tUjzSzxQSxT1Y+RJIZgnP7BVb6Uhi+9cjxqA==", + "optional": true, "requires": { "chromium-pickle-js": "^0.2.0", "commander": "^2.20.0", @@ -1367,12 +1378,14 @@ "commander": { "version": "2.20.1", "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.1.tgz", - "integrity": "sha512-cCuLsMhJeWQ/ZpsFTbE765kvVfoeSddc4nU3up4fV+fDBcfUXnbITJ+JzhkdjzOqhURjZgujxaioam4RM9yGUg==" + "integrity": "sha512-cCuLsMhJeWQ/ZpsFTbE765kvVfoeSddc4nU3up4fV+fDBcfUXnbITJ+JzhkdjzOqhURjZgujxaioam4RM9yGUg==", + "optional": true }, "glob": { "version": "7.1.4", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.4.tgz", "integrity": "sha512-hkLPepehmnKk41pUGm3sYxoFs/umurYfYJCerbXEyFIWcAzvpipAgVkBqqT9RBKMGjnq6kMuyYwha6csxbiM1A==", + "optional": true, "requires": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", @@ -1386,6 +1399,7 @@ "version": "1.1.0", "resolved": "https://registry.npmjs.org/tmp-promise/-/tmp-promise-1.1.0.tgz", "integrity": "sha512-8+Ah9aB1IRXCnIOxXZ0uFozV1nMU5xiu7hhFVUSxZ3bYu+psD4TzagCzVbexUCgNNGJnsmNDQlS4nG3mTyoNkw==", + "optional": true, "requires": { "bluebird": "^3.5.0", "tmp": "0.1.0" @@ -2807,15 +2821,6 @@ "cross-spawn": "^5.1.0" } }, - "cross-zip": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/cross-zip/-/cross-zip-3.0.0.tgz", - "integrity": "sha512-cm+l8PJ6WiSQmKZ/x8DGvUm2u/3FX2JFs1AFd18gdHaVhP5Lf4oE6Jrj2Jd05JYSioz5x+nIRVp0zBQuzuCRcQ==", - "dev": true, - "requires": { - "rimraf": "^3.0.0" - } - }, "crypto-random-string": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/crypto-random-string/-/crypto-random-string-2.0.0.tgz", @@ -2906,7 +2911,8 @@ "cuint": { "version": "0.2.2", "resolved": "https://registry.npmjs.org/cuint/-/cuint-0.2.2.tgz", - "integrity": "sha1-QICG1AlVDCYxFVYZ6fp7ytw7mRs=" + "integrity": "sha1-QICG1AlVDCYxFVYZ6fp7ytw7mRs=", + "optional": true }, "currently-unhandled": { "version": "0.4.1", @@ -3290,11 +3296,6 @@ } } }, - "dns-prefetch-control": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/dns-prefetch-control/-/dns-prefetch-control-0.2.0.tgz", - "integrity": "sha512-hvSnros73+qyZXhHFjx2CMLwoj3Fe7eR9EJsFsqmcI1bB2OBWL/+0YzaEaKssCHnj/6crawNnUyw74Gm2EKe+Q==" - }, "dom-serializer": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-0.1.1.tgz", @@ -3736,32 +3737,19 @@ } }, "electron-notarize": { - "version": "0.2.1", - "resolved": "https://registry.npmjs.org/electron-notarize/-/electron-notarize-0.2.1.tgz", - "integrity": "sha512-oZ6/NhKeXmEKNROiFmRNfytqu3cxqC95sjooG7kBXQVEUSQkZnbiAhxVh5jXngL881G197pbwpeVPJyM7Ikmxw==", + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/electron-notarize/-/electron-notarize-1.0.0.tgz", + "integrity": "sha512-dsib1IAquMn0onCrNMJ6gtEIZn/azG8hZMCYOuZIMVMUeRMgBYHK1s5TK9P8xAcrAjh/2aN5WYHzgVSWX314og==", "dev": true, "requires": { "debug": "^4.1.1", - "fs-extra": "^8.1.0" - }, - "dependencies": { - "fs-extra": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz", - "integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==", - "dev": true, - "requires": { - "graceful-fs": "^4.2.0", - "jsonfile": "^4.0.0", - "universalify": "^0.1.0" - } - } + "fs-extra": "^9.0.1" } }, "electron-osx-sign": { - "version": "0.4.15", - "resolved": "https://registry.npmjs.org/electron-osx-sign/-/electron-osx-sign-0.4.15.tgz", - "integrity": "sha512-1QtPNpjIji9bGZ0VRFwtJUyU1uHi7q3XUAOG0qFsvAUfs5H0T8hbgUfyg3xvPzmF1ruV8T8pQmQ86vNfLrcRiA==", + "version": "0.4.17", + "resolved": "https://registry.npmjs.org/electron-osx-sign/-/electron-osx-sign-0.4.17.tgz", + "integrity": "sha512-wUJPmZJQCs1zgdlQgeIpRcvrf7M5/COQaOV68Va1J/SgmWx5KL2otgg+fAae7luw6qz9R8Gvu/Qpe9tAOu/3xQ==", "dev": true, "requires": { "bluebird": "^3.5.0", @@ -3793,18 +3781,19 @@ } }, "electron-packager": { - "version": "14.2.1", - "resolved": "https://registry.npmjs.org/electron-packager/-/electron-packager-14.2.1.tgz", - "integrity": "sha512-g6y3BVrAOz/iavKD+VMFbehrQcwCWuA3CZvVbmmbQuCfegGA1ytwWn0BNIDDrEdbuz31Fti7mnNHhb5L+3Wq9A==", + "version": "15.0.0", + "resolved": "https://registry.npmjs.org/electron-packager/-/electron-packager-15.0.0.tgz", + "integrity": "sha512-J0yQP7/fKPkjxo9Yz5+vsQVig0dBbSXW8LQYA1pvNMvi+bL00hfI2SAyORP6EU7XaeiXGUIBSG2Px01EkKfGCw==", "dev": true, "requires": { "@electron/get": "^1.6.0", - "asar": "^2.0.1", - "cross-zip": "^3.0.0", + "asar": "^3.0.0", "debug": "^4.0.1", - "electron-notarize": "^0.2.0", + "electron-notarize": "^1.0.0", "electron-osx-sign": "^0.4.11", - "fs-extra": "^8.1.0", + "extract-zip": "^2.0.0", + "filenamify": "^4.1.0", + "fs-extra": "^9.0.0", "galactus": "^0.2.1", "get-package-info": "^1.0.0", "junk": "^3.1.0", @@ -3812,27 +3801,80 @@ "plist": "^3.0.0", "rcedit": "^2.0.0", "resolve": "^1.1.6", - "sanitize-filename": "^1.6.0", - "semver": "^6.0.0", - "yargs-parser": "^16.0.0" + "semver": "^7.1.3", + "yargs-parser": "^18.0.0" }, "dependencies": { - "fs-extra": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz", - "integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==", + "asar": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/asar/-/asar-3.0.3.tgz", + "integrity": "sha512-k7zd+KoR+n8pl71PvgElcoKHrVNiSXtw7odKbyNpmgKe7EGRF9Pnu3uLOukD37EvavKwVFxOUpqXTIZC5B5Pmw==", "dev": true, "requires": { - "graceful-fs": "^4.2.0", - "jsonfile": "^4.0.0", - "universalify": "^0.1.0" + "@types/glob": "^7.1.1", + "chromium-pickle-js": "^0.2.0", + "commander": "^5.0.0", + "glob": "^7.1.6", + "minimatch": "^3.0.4" } }, - "semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "commander": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-5.1.0.tgz", + "integrity": "sha512-P0CysNDQ7rtVw4QIQtm+MRxV66vKFSvlsQvGYXZWR3qFU0jlMKHZZZgw8e+8DSah4UDKMqnknRDQz+xuQXQ/Zg==", "dev": true + }, + "extract-zip": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/extract-zip/-/extract-zip-2.0.1.tgz", + "integrity": "sha512-GDhU9ntwuKyGXdZBUgTIe+vXnWj0fppUEtMDL0+idd5Sta8TGpHssn/eusA9mrPr9qNDym6SxAYZjNvCn/9RBg==", + "dev": true, + "requires": { + "@types/yauzl": "^2.9.1", + "debug": "^4.1.1", + "get-stream": "^5.1.0", + "yauzl": "^2.10.0" + } + }, + "filename-reserved-regex": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/filename-reserved-regex/-/filename-reserved-regex-2.0.0.tgz", + "integrity": "sha1-q/c9+rc10EVECr/qLZHzieu/oik=", + "dev": true + }, + "filenamify": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/filenamify/-/filenamify-4.1.0.tgz", + "integrity": "sha512-KQV/uJDI9VQgN7sHH1Zbk6+42cD6mnQ2HONzkXUfPJ+K2FC8GZ1dpewbbHw0Sz8Tf5k3EVdHVayM4DoAwWlmtg==", + "dev": true, + "requires": { + "filename-reserved-regex": "^2.0.0", + "strip-outer": "^1.0.1", + "trim-repeated": "^1.0.0" + } + }, + "get-stream": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.1.0.tgz", + "integrity": "sha512-EXr1FOzrzTfGeL0gQdeFEvOMm2mzMOglyiOXSTpPC+iAjAKftbr3jpCMWynogwYnM+eSj9sHGc6wjIcDvYiygw==", + "dev": true, + "requires": { + "pump": "^3.0.0" + } + }, + "glob": { + "version": "7.1.6", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", + "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", + "dev": true, + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } } } }, @@ -4294,11 +4336,6 @@ "resolved": "https://registry.npmjs.org/expand-template/-/expand-template-2.0.3.tgz", "integrity": "sha512-XYfuKMvj4O35f/pOXLObndIRvyQ+/+6AhODh+OKWj9S9498pHHn/IMszH+gt0fBCRWMNfk1ZSp5x3AifmnI2vg==" }, - "expect-ct": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/expect-ct/-/expect-ct-0.2.0.tgz", - "integrity": "sha512-6SK3MG/Bbhm8MsgyJAylg+ucIOU71/FzyFalcfu5nY19dH8y/z0tBJU0wrNBXD4B27EoQtqPF/9wqH0iYAd04g==" - }, "express": { "version": "4.17.1", "resolved": "https://registry.npmjs.org/express/-/express-4.17.1.tgz", @@ -4771,11 +4808,6 @@ "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz", "integrity": "sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ=" }, - "frameguard": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/frameguard/-/frameguard-3.1.0.tgz", - "integrity": "sha512-TxgSKM+7LTA6sidjOiSZK9wxY0ffMPY3Wta//MqwmX0nZuEHc8QrkV8Fh3ZhMJeiH+Uyh/tcaarImRy8u77O7g==" - }, "fresh": { "version": "0.5.2", "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", @@ -5002,12 +5034,6 @@ "pify": "^2.0.0" } }, - "pify": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", - "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=", - "dev": true - }, "read-pkg": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-2.0.0.tgz", @@ -5536,16 +5562,13 @@ "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==" }, "helmet": { - "version": "3.23.1", - "resolved": "https://registry.npmjs.org/helmet/-/helmet-3.23.1.tgz", - "integrity": "sha512-e034HHfRK4065BFjYbffn5jXaTWWrhTNgmLIppsGEOjpdDB1MBQkWlAFW/auULXAu6uKk2X76n7a7gvz5sSjkg==", + "version": "3.23.3", + "resolved": "https://registry.npmjs.org/helmet/-/helmet-3.23.3.tgz", + "integrity": "sha512-U3MeYdzPJQhtvqAVBPntVgAvNSOJyagwZwyKsFdyRa8TV3pOKVFljalPOCxbw5Wwf2kncGhmP0qHjyazIdNdSA==", "requires": { "depd": "2.0.0", - "dns-prefetch-control": "0.2.0", "dont-sniff-mimetype": "1.1.0", - "expect-ct": "0.2.0", "feature-policy": "0.3.0", - "frameguard": "3.1.0", "helmet-crossdomain": "0.4.0", "helmet-csp": "2.10.0", "hide-powered-by": "1.1.0", @@ -7450,11 +7473,6 @@ "resolved": "https://registry.npmjs.org/modify-filename/-/modify-filename-1.1.0.tgz", "integrity": "sha1-mi3sg4Bvuy2XXyK+7IWcoms5OqE=" }, - "moment": { - "version": "2.24.0", - "resolved": "https://registry.npmjs.org/moment/-/moment-2.24.0.tgz", - "integrity": "sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg==" - }, "mozjpeg": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/mozjpeg/-/mozjpeg-7.0.0.tgz", @@ -10430,15 +10448,6 @@ } } }, - "simple-node-logger": { - "version": "18.12.24", - "resolved": "https://registry.npmjs.org/simple-node-logger/-/simple-node-logger-18.12.24.tgz", - "integrity": "sha512-4dTqpYecHsvPjWo+i+J3pLty8WJDNbxOVesNj5ch8pYH95LIGAFH4dxMSqyf+Os0RTchXifEtI/mfm3AVJftmg==", - "requires": { - "lodash": "^4.17.12", - "moment": "^2.20.1" - } - }, "slash": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", @@ -11052,6 +11061,7 @@ "version": "0.1.0", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.1.0.tgz", "integrity": "sha512-J7Z2K08jbGcdA1kkQpJSqLF6T0tdQqpR2pnSUXsIchbPdTI9v3e85cLW0d6WDhwuAleOV71j2xWs8qMPfK7nKw==", + "optional": true, "requires": { "rimraf": "^2.6.3" }, @@ -11060,6 +11070,7 @@ "version": "7.1.4", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.4.tgz", "integrity": "sha512-hkLPepehmnKk41pUGm3sYxoFs/umurYfYJCerbXEyFIWcAzvpipAgVkBqqT9RBKMGjnq6kMuyYwha6csxbiM1A==", + "optional": true, "requires": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", @@ -11073,6 +11084,7 @@ "version": "2.7.1", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", + "optional": true, "requires": { "glob": "^7.1.3" } @@ -12374,9 +12386,9 @@ } }, "yargs-parser": { - "version": "16.1.0", - "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-16.1.0.tgz", - "integrity": "sha512-H/V41UNZQPkUMIT5h5hiwg4QKIY1RPvoBV4XcjUbRM8Bk2oKqqyZ0DIEbTFZB0XjbtSPG8SAa/0DxCQmiRgzKg==", + "version": "18.1.3", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-18.1.3.tgz", + "integrity": "sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ==", "dev": true, "requires": { "camelcase": "^5.0.0", diff --git a/package.json b/package.json index 870cf47be..dfc4739bb 100644 --- a/package.json +++ b/package.json @@ -48,10 +48,6 @@ "http-proxy-agent": "4.0.1", "https-proxy-agent": "5.0.0", "image-type": "4.1.0", - "imagemin": "7.0.1", - "imagemin-giflossy": "5.1.10", - "imagemin-mozjpeg": "9.0.0", - "imagemin-pngquant": "9.0.0", "ini": "1.3.5", "is-svg": "4.2.1", "jimp": "0.13.0", @@ -81,7 +77,7 @@ "cross-env": "^7.0.2", "electron": "10.0.0-beta.4", "electron-builder": "22.7.0", - "electron-packager": "14.2.1", + "electron-packager": "15.0.0", "electron-rebuild": "1.11.0", "esm": "^3.2.25", "jasmine": "^3.5.0", diff --git a/src/services/image.js b/src/services/image.js index cc843bb89..5a5e4facd 100644 --- a/src/services/image.js +++ b/src/services/image.js @@ -5,10 +5,6 @@ const log = require('./log'); const protectedSessionService = require('./protected_session'); const noteService = require('./notes'); const optionService = require('./options'); -const imagemin = require('imagemin'); -const imageminMozJpeg = require('imagemin-mozjpeg'); -const imageminPngQuant = require('imagemin-pngquant'); -const imageminGifLossy = require('imagemin-giflossy'); const jimp = require('jimp'); const imageType = require('image-type'); const sanitizeFilename = require('sanitize-filename'); @@ -23,7 +19,7 @@ function processImage(uploadBuffer, originalName, shrinkImageSwitch) { shrinkImageSwitch = false; } - const finalImageBuffer = shrinkImageSwitch ? shrinkImage(uploadBuffer, originalName) : uploadBuffer; + const finalImageBuffer = shrinkImageSwitch ? shrinkImage(uploadBuffer) : uploadBuffer; const imageFormat = getImageType(finalImageBuffer); @@ -96,19 +92,9 @@ function saveImage(parentNoteId, uploadBuffer, originalName, shrinkImageSwitch) }; } -function shrinkImage(buffer, originalName) { - // we do resizing with max (100) quality which will be trimmed during optimization step next - const resizedImage = resize(buffer, 100); - let finalImageBuffer; - +function shrinkImage(buffer) { const jpegQuality = optionService.getOptionInt('imageJpegQuality'); - - try { - finalImageBuffer = optimize(resizedImage, jpegQuality); - } catch (e) { - log.error("Failed to optimize image '" + originalName + "'\nStack: " + e.stack); - finalImageBuffer = resize(buffer, jpegQuality); - } + let finalImageBuffer = resize(buffer, jpegQuality); // if resizing & shrinking did not help with size then save the original // (can happen when e.g. resizing PNG into JPEG) @@ -139,23 +125,6 @@ function resize(buffer, quality) { return image.getBufferAsync(jimp.MIME_JPEG); } -function optimize(buffer, jpegQuality) { - return imagemin.buffer(buffer, { - plugins: [ - imageminMozJpeg({ - quality: jpegQuality - }), - imageminPngQuant({ - quality: [0, 0.7] - }), - imageminGifLossy({ - lossy: 80, - optimize: '3' // needs to be string - }) - ] - }); -} - module.exports = { saveImage, updateImage