b2b-platform-utils 1.1.40 → 1.1.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/errorsMap.js +6 -0
- package/optimizeMedia.js +42 -1
- package/package.json +1 -1
package/errorsMap.js
CHANGED
|
@@ -563,6 +563,12 @@ const STATIC_ERRORS = [
|
|
|
563
563
|
httpCode: 422,
|
|
564
564
|
description: "Page SEO already exists.",
|
|
565
565
|
},
|
|
566
|
+
{
|
|
567
|
+
errorCode: 1092,
|
|
568
|
+
errorKey: "invalidWithdrawalStatusTransition",
|
|
569
|
+
httpCode: 422,
|
|
570
|
+
description: "Withdrawal status transition is invalid for the current state.",
|
|
571
|
+
},
|
|
566
572
|
];
|
|
567
573
|
|
|
568
574
|
const STATIC_BY_KEY = Object.fromEntries(
|
package/optimizeMedia.js
CHANGED
|
@@ -45,4 +45,45 @@ async function saveGameImageBufferWEBP(fileDataBuffer, quality = 80, maxWidth =
|
|
|
45
45
|
.toBuffer();
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Buffer to WebP for game images: auto-rotate; optional resize when `width` and/or `height` is set (Sharp options).
|
|
50
|
+
* @param {Buffer} fileDataBuffer
|
|
51
|
+
* @param {object} [options]
|
|
52
|
+
* @returns {Promise<Buffer>}
|
|
53
|
+
*/
|
|
54
|
+
async function saveGameImageBufferWEBPWithOptions(fileDataBuffer, options = {}) {
|
|
55
|
+
const {
|
|
56
|
+
quality = 80,
|
|
57
|
+
width,
|
|
58
|
+
height,
|
|
59
|
+
fit = 'inside',
|
|
60
|
+
withoutEnlargement = true,
|
|
61
|
+
effort = 5,
|
|
62
|
+
smartSubsample = true
|
|
63
|
+
} = options;
|
|
64
|
+
|
|
65
|
+
let pipeline = sharp(fileDataBuffer).rotate();
|
|
66
|
+
|
|
67
|
+
if (width != null || height != null) {
|
|
68
|
+
pipeline = pipeline.resize({
|
|
69
|
+
width,
|
|
70
|
+
height,
|
|
71
|
+
fit,
|
|
72
|
+
withoutEnlargement
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return pipeline
|
|
77
|
+
.webp({
|
|
78
|
+
quality,
|
|
79
|
+
effort,
|
|
80
|
+
smartSubsample
|
|
81
|
+
})
|
|
82
|
+
.toBuffer();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
module.exports = {
|
|
86
|
+
optimizeImageBufferWEBP,
|
|
87
|
+
saveGameImageBufferWEBP,
|
|
88
|
+
saveGameImageBufferWEBPWithOptions
|
|
89
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "b2b-platform-utils",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.43",
|
|
4
4
|
"description": "Shared utilities for Node.js microservices: errors map, local cache, logger, numbers, dates, filesystem, media optimization, paginator, slugger, crypto wrapper, sanitize HTML, sorting.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"license": "KingSizer",
|