@tryghost/image-transform 1.2.11 → 1.3.1
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/LICENSE +1 -1
- package/README.md +1 -1
- package/lib/transform.js +9 -4
- package/package.json +5 -5
package/LICENSE
CHANGED
package/README.md
CHANGED
package/lib/transform.js
CHANGED
|
@@ -2,6 +2,8 @@ const errors = require('@tryghost/errors');
|
|
|
2
2
|
const fs = require('fs-extra');
|
|
3
3
|
const path = require('path');
|
|
4
4
|
|
|
5
|
+
const DEFAULT_PROCESSING_TIMEOUT_SECONDS = 0; // 0 means no timeout
|
|
6
|
+
|
|
5
7
|
/**
|
|
6
8
|
* Check if this tool can handle any file transformations as Sharp is an optional dependency
|
|
7
9
|
*/
|
|
@@ -58,13 +60,14 @@ const canTransformToFormat = format => [
|
|
|
58
60
|
* https://github.com/lovell/sharp/issues/1360.
|
|
59
61
|
*
|
|
60
62
|
* Resize an image referenced by the `in` path and write it to the `out` path
|
|
61
|
-
* @param {{in, out, width}} options
|
|
63
|
+
* @param {{in, out, width, timeout}} options
|
|
62
64
|
*/
|
|
63
65
|
const unsafeResizeFromPath = (options = {}) => {
|
|
64
66
|
return fs.readFile(options.in)
|
|
65
67
|
.then((data) => {
|
|
66
68
|
return unsafeResizeFromBuffer(data, {
|
|
67
|
-
width: options.width
|
|
69
|
+
width: options.width,
|
|
70
|
+
timeout: options.timeout
|
|
68
71
|
});
|
|
69
72
|
})
|
|
70
73
|
.then((data) => {
|
|
@@ -76,7 +79,7 @@ const unsafeResizeFromPath = (options = {}) => {
|
|
|
76
79
|
* Resize an image
|
|
77
80
|
*
|
|
78
81
|
* @param {Buffer} originalBuffer image to resize
|
|
79
|
-
* @param {{width?: number, height?: number, format?: keyof import('sharp').FormatEnum, animated?: boolean, withoutEnlargement?: boolean}} [options]
|
|
82
|
+
* @param {{width?: number, height?: number, format?: keyof import('sharp').FormatEnum, animated?: boolean, withoutEnlargement?: boolean, timeout:? number}} [options]
|
|
80
83
|
* options.animated defaults to true for file formats where animation is supported (will always maintain animation if possible)
|
|
81
84
|
* @returns {Promise<Buffer>} the resizedBuffer
|
|
82
85
|
*/
|
|
@@ -105,7 +108,8 @@ const unsafeResizeFromBuffer = async (originalBuffer, options = {}) => {
|
|
|
105
108
|
withoutEnlargement: options.withoutEnlargement ?? true
|
|
106
109
|
})
|
|
107
110
|
// CASE: Automatically remove metadata and rotate based on the orientation.
|
|
108
|
-
.rotate()
|
|
111
|
+
.rotate()
|
|
112
|
+
.timeout({seconds: options.timeout || DEFAULT_PROCESSING_TIMEOUT_SECONDS});
|
|
109
113
|
|
|
110
114
|
const metadata = await s.metadata();
|
|
111
115
|
|
|
@@ -162,3 +166,4 @@ module.exports.canTransformToFormat = canTransformToFormat;
|
|
|
162
166
|
module.exports.generateOriginalImageName = generateOriginalImageName;
|
|
163
167
|
module.exports.resizeFromPath = makeSafe(unsafeResizeFromPath);
|
|
164
168
|
module.exports.resizeFromBuffer = makeSafe(unsafeResizeFromBuffer);
|
|
169
|
+
module.exports.DEFAULT_PROCESSING_TIMEOUT_SECONDS = DEFAULT_PROCESSING_TIMEOUT_SECONDS;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/image-transform",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"repository": "https://github.com/TryGhost/SDK/tree/main/packages/image-transform",
|
|
5
5
|
"author": "Ghost Foundation",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
"access": "public"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"c8": "
|
|
23
|
-
"mocha": "
|
|
22
|
+
"c8": "10.1.3",
|
|
23
|
+
"mocha": "11.1.0",
|
|
24
24
|
"should": "13.2.3",
|
|
25
|
-
"sinon": "
|
|
25
|
+
"sinon": "20.0.0"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@tryghost/errors": "^1.2.26",
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"optionalDependencies": {
|
|
32
32
|
"sharp": "^0.32.0"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "19592ba6684cd896674e6bd1da92e3eb06e665f2"
|
|
35
35
|
}
|