@websolutespa/bom-mixer-image 1.8.4 → 2.0.1-next.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.
package/CHANGELOG.md CHANGED
@@ -1,104 +1,115 @@
1
- # @websolutespa/bom-mixer-image
2
-
3
- ## 1.8.4
4
-
5
- ### Patch Changes
6
-
7
- - Fixing: handling latin1 src
8
-
9
- ## 1.8.3
10
-
11
- ### Patch Changes
12
-
13
- - Added: ImageStrategy.Token
14
- - Updated dependencies
15
- - @websolutespa/bom-core@1.8.4
16
-
17
- ## 1.8.2
18
-
19
- ### Patch Changes
20
-
21
- - Modified: imageHandler
22
-
23
- ## 1.8.1
24
-
25
- ### Patch Changes
26
-
27
- - Modified: imageHandler
28
-
29
- ## 1.8.0
30
-
31
- ### Patch Changes
32
-
33
- - Updated dependencies [f8a1d97]
34
- - @websolutespa/bom-core@1.8.0
35
-
36
- ## 1.0.9
37
-
38
- ### Patch Changes
39
-
40
- - Fixing: downgrading eslint to v8.56.0
41
- - Updated dependencies
42
- - @websolutespa/bom-core@1.7.8
43
-
44
- ## 1.0.8
45
-
46
- ### Patch Changes
47
-
48
- - Added: Cache-Control
49
-
50
- ## 1.0.7
51
-
52
- ### Patch Changes
53
-
54
- - Fixing: imageHandler Vercel support
55
- - Updated dependencies
56
- - @websolutespa/bom-core@1.7.7
57
-
58
- ## 1.0.6
59
-
60
- ### Patch Changes
61
-
62
- - Modified: imageHandler, re-route not found to origin
63
-
64
- ## 1.0.5
65
-
66
- ### Patch Changes
67
-
68
- - Modified: imageHandler
69
- - Updated dependencies
70
- - @websolutespa/bom-core@1.7.6
71
-
72
- ## 1.0.4
73
-
74
- ### Patch Changes
75
-
76
- - Modified: imageHandler getOriginalImage
77
- - Updated dependencies
78
- - @websolutespa/bom-core@1.7.5
79
-
80
- ## 1.0.3
81
-
82
- ### Patch Changes
83
-
84
- - 43957d4: Fixing: production local asset public path
85
- - Updated dependencies
86
- - @websolutespa/bom-core@1.7.4
87
-
88
- ## 1.0.2
89
-
90
- ### Patch Changes
91
-
92
- - 75b1311: Fixing: relative paths
93
-
94
- ## 1.0.1
95
-
96
- ### Patch Changes
97
-
98
- - Updating: dependencies
99
-
100
- ## 1.0.0
101
-
102
- ### Patch Changes
103
-
104
- - Added: first release
1
+ # @websolutespa/bom-mixer-image
2
+
3
+ ## 2.0.1-next.0
4
+
5
+ ### Major Changes
6
+
7
+ - e74b305: Release: Payload 3.7.0
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [e74b305]
12
+ - @websolutespa/bom-core@2.0.1-next.0
13
+
14
+ ## 1.8.4
15
+
16
+ ### Patch Changes
17
+
18
+ - Fixing: handling latin1 src
19
+
20
+ ## 1.8.3
21
+
22
+ ### Patch Changes
23
+
24
+ - Added: ImageStrategy.Token
25
+ - Updated dependencies
26
+ - @websolutespa/bom-core@1.8.4
27
+
28
+ ## 1.8.2
29
+
30
+ ### Patch Changes
31
+
32
+ - Modified: imageHandler
33
+
34
+ ## 1.8.1
35
+
36
+ ### Patch Changes
37
+
38
+ - Modified: imageHandler
39
+
40
+ ## 1.8.0
41
+
42
+ ### Patch Changes
43
+
44
+ - Updated dependencies [f8a1d97]
45
+ - @websolutespa/bom-core@1.8.0
46
+
47
+ ## 1.0.9
48
+
49
+ ### Patch Changes
50
+
51
+ - Fixing: downgrading eslint to v8.56.0
52
+ - Updated dependencies
53
+ - @websolutespa/bom-core@1.7.8
54
+
55
+ ## 1.0.8
56
+
57
+ ### Patch Changes
58
+
59
+ - Added: Cache-Control
60
+
61
+ ## 1.0.7
62
+
63
+ ### Patch Changes
64
+
65
+ - Fixing: imageHandler Vercel support
66
+ - Updated dependencies
67
+ - @websolutespa/bom-core@1.7.7
68
+
69
+ ## 1.0.6
70
+
71
+ ### Patch Changes
72
+
73
+ - Modified: imageHandler, re-route not found to origin
74
+
75
+ ## 1.0.5
76
+
77
+ ### Patch Changes
78
+
79
+ - Modified: imageHandler
80
+ - Updated dependencies
81
+ - @websolutespa/bom-core@1.7.6
82
+
83
+ ## 1.0.4
84
+
85
+ ### Patch Changes
86
+
87
+ - Modified: imageHandler getOriginalImage
88
+ - Updated dependencies
89
+ - @websolutespa/bom-core@1.7.5
90
+
91
+ ## 1.0.3
92
+
93
+ ### Patch Changes
94
+
95
+ - 43957d4: Fixing: production local asset public path
96
+ - Updated dependencies
97
+ - @websolutespa/bom-core@1.7.4
98
+
99
+ ## 1.0.2
100
+
101
+ ### Patch Changes
102
+
103
+ - 75b1311: Fixing: relative paths
104
+
105
+ ## 1.0.1
106
+
107
+ ### Patch Changes
108
+
109
+ - Updating: dependencies
110
+
111
+ ## 1.0.0
112
+
113
+ ### Patch Changes
114
+
115
+ - Added: first release
@@ -1,8 +1,44 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ imageHandler: () => imageHandler
34
+ });
35
+ module.exports = __toCommonJS(index_exports);
36
+
1
37
  // src/image/image.handler.ts
2
- import * as fs from "fs";
3
- import * as path from "path";
4
- import sharp from "sharp";
5
- import { decryptImageResize, ImageStrategy } from "@websolutespa/bom-core";
38
+ var fs = __toESM(require("fs"), 1);
39
+ var path = __toESM(require("path"), 1);
40
+ var import_sharp = __toESM(require("sharp"), 1);
41
+ var import_bom_core = require("@websolutespa/bom-core");
6
42
 
7
43
  // src/api/api.handler.ts
8
44
  function apiHandler(handler) {
@@ -32,7 +68,7 @@ function errorHandler(error, response) {
32
68
  }
33
69
 
34
70
  // src/image/image.handler.ts
35
- var IMAGE_STRATEGY = process.env.IMAGE_STRATEGY ? process.env.IMAGE_STRATEGY : ImageStrategy.Mixer;
71
+ var IMAGE_STRATEGY = process.env.IMAGE_STRATEGY ? process.env.IMAGE_STRATEGY : import_bom_core.ImageStrategy.Mixer;
36
72
  var IMAGE_MAX_AGE = 604800;
37
73
  var IMAGE_FOCAL_X = 50;
38
74
  var IMAGE_FOCAL_Y = 50;
@@ -48,7 +84,7 @@ function imageHandler({
48
84
  try {
49
85
  let imageOptions;
50
86
  try {
51
- imageOptions = IMAGE_STRATEGY === ImageStrategy.Token ? getEncryptedImageOptions(request, { domains, sizes, quality }) : getImageOptions(request, { domains, sizes, quality });
87
+ imageOptions = IMAGE_STRATEGY === import_bom_core.ImageStrategy.Token ? getEncryptedImageOptions(request, { domains, sizes, quality }) : getImageOptions(request, { domains, sizes, quality });
52
88
  } catch (error) {
53
89
  return response.status(400).json({
54
90
  errors: [{
@@ -72,7 +108,9 @@ function imageHandler({
72
108
  }
73
109
  const originalImageBuffer = await getOriginalImage(imageOptions.url, domains, request.headers);
74
110
  if (originalImageBuffer) {
75
- const originalImage = sharp(originalImageBuffer);
111
+ const originalImage = (0, import_sharp.default)(originalImageBuffer, {
112
+ animated: isGIF(imageOptions.url)
113
+ });
76
114
  const resizedImage = await resizeImage(originalImage, imageOptions);
77
115
  const compressedImage = resizedImage.webp({
78
116
  quality: imageOptions.q
@@ -96,11 +134,14 @@ function imageHandler({
96
134
  }
97
135
  });
98
136
  }
137
+ function isGIF(src) {
138
+ return src.indexOf(".gif") !== -1;
139
+ }
99
140
  function isInvalidReferer(request) {
100
141
  const { headers } = request;
101
142
  const referer = headers.referer;
102
143
  const publicUrl = process.env.NEXT_PUBLIC_URL || "";
103
- if (IMAGE_STRATEGY !== ImageStrategy.Token && referer && publicUrl !== "https://" && referer.indexOf(publicUrl) !== 0) {
144
+ if (IMAGE_STRATEGY !== import_bom_core.ImageStrategy.Token && referer && publicUrl !== "https://" && referer.indexOf(publicUrl) !== 0) {
104
145
  return true;
105
146
  }
106
147
  return false;
@@ -152,7 +193,7 @@ function getEncryptedImageOptions(request, options) {
152
193
  if (typeof t !== "string") {
153
194
  throw "missing t parameter";
154
195
  }
155
- const imageResize = decryptImageResize(t);
196
+ const imageResize = (0, import_bom_core.decryptImageResize)(t);
156
197
  imageResize.src = decodeURIComponent(imageResize.src);
157
198
  const url = decodeURIComponent(origin + "/" + slugs.join("/") + search);
158
199
  if (imageResize.src !== url) {
@@ -171,8 +212,8 @@ async function resizeImage(originalImage, imageOptions) {
171
212
  return originalImage.resize({
172
213
  width: resizeWidth,
173
214
  height: resizeHeight ? resizeHeight : void 0,
174
- fit: sharp.fit.cover,
175
- position: sharp.strategy.attention,
215
+ fit: import_sharp.default.fit.cover,
216
+ position: import_sharp.default.strategy.attention,
176
217
  withoutEnlargement: true
177
218
  });
178
219
  };
@@ -185,10 +226,10 @@ async function resizeImage(originalImage, imageOptions) {
185
226
  const imageToResize = originalImage.clone();
186
227
  const scaledImage = imageToResize.resize(prioritizeHeight ? {
187
228
  height: resizeHeight,
188
- fit: sharp.fit.cover
229
+ fit: import_sharp.default.fit.cover
189
230
  } : {
190
231
  width: resizeWidth,
191
- fit: sharp.fit.cover
232
+ fit: import_sharp.default.fit.cover
192
233
  });
193
234
  const { info: scaledImageInfo } = await scaledImage.toBuffer({ resolveWithObject: true });
194
235
  const extractWidth = resizeWidth ?? scaledImageInfo.width;
@@ -283,12 +324,13 @@ function urlToCachedName(options) {
283
324
  return cachedName;
284
325
  }
285
326
  function isInvalidDomain(src, domains) {
286
- if (IMAGE_STRATEGY === ImageStrategy.Token) {
327
+ if (IMAGE_STRATEGY === import_bom_core.ImageStrategy.Token) {
287
328
  return false;
288
329
  }
289
330
  const url = new URL(src);
290
331
  return !domains.includes(url.hostname);
291
332
  }
292
- export {
333
+ // Annotate the CommonJS export names for ESM import in node:
334
+ 0 && (module.exports = {
293
335
  imageHandler
294
- };
336
+ });
@@ -0,0 +1,15 @@
1
+ import { IImageResize } from '@websolutespa/bom-core';
2
+
3
+ type IImageHandlerOptions = {
4
+ domains: string[];
5
+ sizes: number[];
6
+ quality: number;
7
+ };
8
+ type IImageOptions = IImageResize & {
9
+ origin: string;
10
+ search: string;
11
+ url: string;
12
+ };
13
+ declare function imageHandler({ domains, sizes, quality, }: IImageHandlerOptions): any;
14
+
15
+ export { type IImageHandlerOptions, type IImageOptions, imageHandler };
package/dist/index.d.ts CHANGED
@@ -12,4 +12,4 @@ type IImageOptions = IImageResize & {
12
12
  };
13
13
  declare function imageHandler({ domains, sizes, quality, }: IImageHandlerOptions): any;
14
14
 
15
- export { IImageHandlerOptions, IImageOptions, imageHandler };
15
+ export { type IImageHandlerOptions, type IImageOptions, imageHandler };
package/dist/index.js CHANGED
@@ -1,44 +1,8 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/index.ts
31
- var src_exports = {};
32
- __export(src_exports, {
33
- imageHandler: () => imageHandler
34
- });
35
- module.exports = __toCommonJS(src_exports);
36
-
37
1
  // src/image/image.handler.ts
38
- var fs = __toESM(require("fs"));
39
- var path = __toESM(require("path"));
40
- var import_sharp = __toESM(require("sharp"));
41
- var import_bom_core = require("@websolutespa/bom-core");
2
+ import * as fs from "fs";
3
+ import * as path from "path";
4
+ import sharp from "sharp";
5
+ import { decryptImageResize, ImageStrategy } from "@websolutespa/bom-core";
42
6
 
43
7
  // src/api/api.handler.ts
44
8
  function apiHandler(handler) {
@@ -68,7 +32,7 @@ function errorHandler(error, response) {
68
32
  }
69
33
 
70
34
  // src/image/image.handler.ts
71
- var IMAGE_STRATEGY = process.env.IMAGE_STRATEGY ? process.env.IMAGE_STRATEGY : import_bom_core.ImageStrategy.Mixer;
35
+ var IMAGE_STRATEGY = process.env.IMAGE_STRATEGY ? process.env.IMAGE_STRATEGY : ImageStrategy.Mixer;
72
36
  var IMAGE_MAX_AGE = 604800;
73
37
  var IMAGE_FOCAL_X = 50;
74
38
  var IMAGE_FOCAL_Y = 50;
@@ -84,7 +48,7 @@ function imageHandler({
84
48
  try {
85
49
  let imageOptions;
86
50
  try {
87
- imageOptions = IMAGE_STRATEGY === import_bom_core.ImageStrategy.Token ? getEncryptedImageOptions(request, { domains, sizes, quality }) : getImageOptions(request, { domains, sizes, quality });
51
+ imageOptions = IMAGE_STRATEGY === ImageStrategy.Token ? getEncryptedImageOptions(request, { domains, sizes, quality }) : getImageOptions(request, { domains, sizes, quality });
88
52
  } catch (error) {
89
53
  return response.status(400).json({
90
54
  errors: [{
@@ -108,7 +72,9 @@ function imageHandler({
108
72
  }
109
73
  const originalImageBuffer = await getOriginalImage(imageOptions.url, domains, request.headers);
110
74
  if (originalImageBuffer) {
111
- const originalImage = (0, import_sharp.default)(originalImageBuffer);
75
+ const originalImage = sharp(originalImageBuffer, {
76
+ animated: isGIF(imageOptions.url)
77
+ });
112
78
  const resizedImage = await resizeImage(originalImage, imageOptions);
113
79
  const compressedImage = resizedImage.webp({
114
80
  quality: imageOptions.q
@@ -132,11 +98,14 @@ function imageHandler({
132
98
  }
133
99
  });
134
100
  }
101
+ function isGIF(src) {
102
+ return src.indexOf(".gif") !== -1;
103
+ }
135
104
  function isInvalidReferer(request) {
136
105
  const { headers } = request;
137
106
  const referer = headers.referer;
138
107
  const publicUrl = process.env.NEXT_PUBLIC_URL || "";
139
- if (IMAGE_STRATEGY !== import_bom_core.ImageStrategy.Token && referer && publicUrl !== "https://" && referer.indexOf(publicUrl) !== 0) {
108
+ if (IMAGE_STRATEGY !== ImageStrategy.Token && referer && publicUrl !== "https://" && referer.indexOf(publicUrl) !== 0) {
140
109
  return true;
141
110
  }
142
111
  return false;
@@ -188,7 +157,7 @@ function getEncryptedImageOptions(request, options) {
188
157
  if (typeof t !== "string") {
189
158
  throw "missing t parameter";
190
159
  }
191
- const imageResize = (0, import_bom_core.decryptImageResize)(t);
160
+ const imageResize = decryptImageResize(t);
192
161
  imageResize.src = decodeURIComponent(imageResize.src);
193
162
  const url = decodeURIComponent(origin + "/" + slugs.join("/") + search);
194
163
  if (imageResize.src !== url) {
@@ -207,8 +176,8 @@ async function resizeImage(originalImage, imageOptions) {
207
176
  return originalImage.resize({
208
177
  width: resizeWidth,
209
178
  height: resizeHeight ? resizeHeight : void 0,
210
- fit: import_sharp.default.fit.cover,
211
- position: import_sharp.default.strategy.attention,
179
+ fit: sharp.fit.cover,
180
+ position: sharp.strategy.attention,
212
181
  withoutEnlargement: true
213
182
  });
214
183
  };
@@ -221,10 +190,10 @@ async function resizeImage(originalImage, imageOptions) {
221
190
  const imageToResize = originalImage.clone();
222
191
  const scaledImage = imageToResize.resize(prioritizeHeight ? {
223
192
  height: resizeHeight,
224
- fit: import_sharp.default.fit.cover
193
+ fit: sharp.fit.cover
225
194
  } : {
226
195
  width: resizeWidth,
227
- fit: import_sharp.default.fit.cover
196
+ fit: sharp.fit.cover
228
197
  });
229
198
  const { info: scaledImageInfo } = await scaledImage.toBuffer({ resolveWithObject: true });
230
199
  const extractWidth = resizeWidth ?? scaledImageInfo.width;
@@ -319,13 +288,12 @@ function urlToCachedName(options) {
319
288
  return cachedName;
320
289
  }
321
290
  function isInvalidDomain(src, domains) {
322
- if (IMAGE_STRATEGY === import_bom_core.ImageStrategy.Token) {
291
+ if (IMAGE_STRATEGY === ImageStrategy.Token) {
323
292
  return false;
324
293
  }
325
294
  const url = new URL(src);
326
295
  return !domains.includes(url.hostname);
327
296
  }
328
- // Annotate the CommonJS export names for ESM import in node:
329
- 0 && (module.exports = {
297
+ export {
330
298
  imageHandler
331
- });
299
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@websolutespa/bom-mixer-image",
3
- "version": "1.8.4",
3
+ "version": "2.0.1-next.0",
4
4
  "description": "Mixer Image module of the BOM Repository",
5
5
  "keywords": [
6
6
  "bom",
@@ -14,37 +14,39 @@
14
14
  },
15
15
  "scripts": {
16
16
  "lint": "eslint *.ts*",
17
- "test": "jest",
18
- "test-watch": "npm test -- --watch --silent=false",
19
- "coverage:integration": "npm run test -- --coverage",
17
+ "test": "vitest run",
18
+ "test-watch": "vitest",
19
+ "coverage:integration": "npm run test -- --coverage.enabled --coverage.provider=istanbul --coverage.all",
20
20
  "coverage": "run-s -c --silent coverage:*",
21
21
  "compile": "tsup ./src/index.ts --format esm,cjs --dts",
22
22
  "prepack": "bom prepack",
23
- "postpack": "bom postpack"
23
+ "postpack": "bom postpack",
24
+ "types": "tsc --noemit"
24
25
  },
25
26
  "dependencies": {},
26
27
  "peerDependencies": {
27
- "@websolutespa/bom-core": "*",
28
- "next": ">= 14.1.4",
29
- "sharp": ">= 0.30.4"
28
+ "@websolutespa/bom-core": "2.0.1-next.0",
29
+ "next": "15.4.10",
30
+ "sharp": "0.34.2"
30
31
  },
31
32
  "devDependencies": {
32
33
  "@types/sharp": "^0.30.4",
33
- "@websolutespa/bom-cli": "*",
34
- "@websolutespa/test": "*",
35
- "@websolutespa/tsconfig": "*",
36
- "eslint": "^8.56.0",
37
- "eslint-config-websolute": "*",
38
- "npm-run-all": "^4.1.5",
39
- "sharp": "0.30.4",
40
- "ts-node": "^10.9.1",
41
- "tsup": "^6.7.0",
42
- "typescript": "^5.4.5"
34
+ "@websolutespa/bom-cli": "2.0.1-next.0",
35
+ "@websolutespa/test": "2.0.1-next.0",
36
+ "@websolutespa/tsconfig": "2.0.1-next.0",
37
+ "eslint": "9.31.0",
38
+ "@websolutespa/eslint-config": "2.0.1-next.0",
39
+ "npm-run-all": "4.1.5",
40
+ "sharp": "0.34.2",
41
+ "ts-node": "^10.9.2",
42
+ "tsup": "8.5.0",
43
+ "typescript": "5.8.3"
43
44
  },
44
45
  "publishConfig": {
45
46
  "access": "public"
46
47
  },
47
48
  "sideEffects": false,
49
+ "type": "module",
48
50
  "prepack": {
49
51
  "types": "./dist/index.d.ts",
50
52
  "main": "./dist/index.js",
@@ -1,4 +1,4 @@
1
- import '@testing-library/jest-dom';
1
+ import { describe, expect, it } from 'vitest';
2
2
 
3
3
  describe('Example', () => {
4
4
  it('passes', async () => {
@@ -84,7 +84,9 @@ export function imageHandler({
84
84
  // Checking if the original image exists
85
85
  if (originalImageBuffer) {
86
86
  // Original image
87
- const originalImage = sharp(originalImageBuffer);
87
+ const originalImage = sharp(originalImageBuffer, {
88
+ animated: isGIF(imageOptions.url),
89
+ });
88
90
  // Resizing the original image and converting it to WebP format
89
91
  const resizedImage = await resizeImage(originalImage, imageOptions);
90
92
  // Converting resized image to WebP format
@@ -121,6 +123,10 @@ export function imageHandler({
121
123
  });
122
124
  }
123
125
 
126
+ function isGIF(src: string): boolean {
127
+ return src.indexOf('.gif') !== -1;
128
+ }
129
+
124
130
  function isInvalidReferer(request: NextApiRequest): boolean {
125
131
  const { headers } = request;
126
132
  const referer = headers.referer;
@@ -359,7 +365,7 @@ function getCachedImage(pathname: string): Promise<Buffer> {
359
365
  function urlToFileName(url: string): string {
360
366
  // Replacing useless characters with UNDERSCORE
361
367
  const segments = url.split('?');
362
- const path = segments[0];
368
+ const path = segments[0]!;
363
369
  const query = segments[1];
364
370
  let uniqueName = path.replace('://', '_').replace(/\.|\/|\?|=/g, '_');
365
371
  // Replacing last UNDERSCORE with a DOT