@tryghost/image-transform 1.2.11 → 1.3.0

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.
Files changed (2) hide show
  1. package/lib/transform.js +9 -4
  2. package/package.json +4 -4
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.2.11",
3
+ "version": "1.3.0",
4
4
  "repository": "https://github.com/TryGhost/SDK/tree/main/packages/image-transform",
5
5
  "author": "Ghost Foundation",
6
6
  "license": "MIT",
@@ -19,8 +19,8 @@
19
19
  "access": "public"
20
20
  },
21
21
  "devDependencies": {
22
- "c8": "8.0.1",
23
- "mocha": "10.2.0",
22
+ "c8": "9.1.0",
23
+ "mocha": "10.4.0",
24
24
  "should": "13.2.3",
25
25
  "sinon": "17.0.1"
26
26
  },
@@ -31,5 +31,5 @@
31
31
  "optionalDependencies": {
32
32
  "sharp": "^0.32.0"
33
33
  },
34
- "gitHead": "4839d3f97de2120d98fa47677eed7591dfa20e64"
34
+ "gitHead": "048ccde4bd78d2dcd60e778d03eb8dc3227cece5"
35
35
  }