@websolutespa/bom-mixer-image 1.0.2 → 1.0.3

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,19 +1,27 @@
1
- # @websolutespa/bom-mixer-image
2
-
3
- ## 1.0.2
4
-
5
- ### Patch Changes
6
-
7
- - 75b1311: Fixing: relative paths
8
-
9
- ## 1.0.1
10
-
11
- ### Patch Changes
12
-
13
- - Updating: dependencies
14
-
15
- ## 1.0.0
16
-
17
- ### Patch Changes
18
-
19
- - Added: first release
1
+ # @websolutespa/bom-mixer-image
2
+
3
+ ## 1.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 43957d4: Fixing: production local asset public path
8
+ - Updated dependencies
9
+ - @websolutespa/bom-core@1.7.4
10
+
11
+ ## 1.0.2
12
+
13
+ ### Patch Changes
14
+
15
+ - 75b1311: Fixing: relative paths
16
+
17
+ ## 1.0.1
18
+
19
+ ### Patch Changes
20
+
21
+ - Updating: dependencies
22
+
23
+ ## 1.0.0
24
+
25
+ ### Patch Changes
26
+
27
+ - Added: first release
package/dist/index.js CHANGED
@@ -38,6 +38,7 @@ module.exports = __toCommonJS(src_exports);
38
38
  var fs = __toESM(require("fs"));
39
39
  var path = __toESM(require("path"));
40
40
  var import_sharp = __toESM(require("sharp"));
41
+ var import_bom_core = require("@websolutespa/bom-core");
41
42
 
42
43
  // src/api/api.handler.ts
43
44
  function apiHandler(handler) {
@@ -100,8 +101,12 @@ function imageHandler({ domains = [] }) {
100
101
  width,
101
102
  height: height ? height : void 0,
102
103
  fit: import_sharp.default.fit.cover,
103
- position: import_sharp.default.strategy.entropy
104
- }).webp({ quality });
104
+ position: import_sharp.default.strategy.entropy,
105
+ withoutEnlargement: true
106
+ }).webp({
107
+ quality,
108
+ nearLossless: true
109
+ });
105
110
  resizedImage.toFile(cachedName).then(() => console.log("imageHandler.sharp.cached", cachedName)).catch((error) => console.error("error caching image", cachedName, error));
106
111
  const data = await resizedImage.toBuffer();
107
112
  return response.end(data);
@@ -139,7 +144,9 @@ function getOriginalImage(url, domains) {
139
144
  return reject(error);
140
145
  });
141
146
  } else {
142
- fs.readFile(url, (error, data) => {
147
+ const isProduction = (0, import_bom_core.getIsProduction)();
148
+ const filePath = isProduction ? path.join(process.cwd(), url) : path.join(process.cwd(), "public", url);
149
+ fs.readFile(filePath, (error, data) => {
143
150
  if (error) {
144
151
  return reject(error);
145
152
  }
package/dist/index.mjs CHANGED
@@ -2,6 +2,7 @@
2
2
  import * as fs from "fs";
3
3
  import * as path from "path";
4
4
  import sharp from "sharp";
5
+ import { getIsProduction } from "@websolutespa/bom-core";
5
6
 
6
7
  // src/api/api.handler.ts
7
8
  function apiHandler(handler) {
@@ -64,8 +65,12 @@ function imageHandler({ domains = [] }) {
64
65
  width,
65
66
  height: height ? height : void 0,
66
67
  fit: sharp.fit.cover,
67
- position: sharp.strategy.entropy
68
- }).webp({ quality });
68
+ position: sharp.strategy.entropy,
69
+ withoutEnlargement: true
70
+ }).webp({
71
+ quality,
72
+ nearLossless: true
73
+ });
69
74
  resizedImage.toFile(cachedName).then(() => console.log("imageHandler.sharp.cached", cachedName)).catch((error) => console.error("error caching image", cachedName, error));
70
75
  const data = await resizedImage.toBuffer();
71
76
  return response.end(data);
@@ -103,7 +108,9 @@ function getOriginalImage(url, domains) {
103
108
  return reject(error);
104
109
  });
105
110
  } else {
106
- fs.readFile(url, (error, data) => {
111
+ const isProduction = getIsProduction();
112
+ const filePath = isProduction ? path.join(process.cwd(), url) : path.join(process.cwd(), "public", url);
113
+ fs.readFile(filePath, (error, data) => {
107
114
  if (error) {
108
115
  return reject(error);
109
116
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@websolutespa/bom-mixer-image",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Mixer Image module of the BOM Repository",
5
5
  "keywords": [
6
6
  "bom",
@@ -24,6 +24,7 @@
24
24
  },
25
25
  "dependencies": {},
26
26
  "peerDependencies": {
27
+ "@websolutespa/bom-core": "*",
27
28
  "next": ">= 13.4.19",
28
29
  "sharp": ">= 0.30.4"
29
30
  },
@@ -7,6 +7,7 @@ import * as path from 'path';
7
7
  // Importing 'sharp' for image processing
8
8
  import sharp from 'sharp';
9
9
  // Importing 'apiHandler' from '../api/api.handler'
10
+ import { getIsProduction } from '@websolutespa/bom-core';
10
11
  import { apiHandler } from '../api/api.handler';
11
12
 
12
13
  const IMAGE_MAX_AGE = 604800;
@@ -67,8 +68,12 @@ export function imageHandler({ domains = [] }: { domains: string[] }) {
67
68
  height: height ? height : undefined,
68
69
  fit: sharp.fit.cover,
69
70
  position: sharp.strategy.entropy,
71
+ withoutEnlargement: true,
70
72
  })
71
- .webp({ quality });
73
+ .webp({
74
+ quality,
75
+ nearLossless: true,
76
+ });
72
77
  // Saving the resized image to the cache
73
78
  resizedImage.toFile(cachedName)
74
79
  .then(() => console.log('imageHandler.sharp.cached', cachedName))
@@ -120,7 +125,11 @@ function getOriginalImage(url: string, domains: string[]): Promise<Buffer> {
120
125
  });
121
126
  } else {
122
127
  // Reading the image from the file system
123
- fs.readFile(path.join(process.cwd(), 'public', url), (error, data) => {
128
+ const isProduction = getIsProduction();
129
+ const filePath = isProduction ?
130
+ path.join(process.cwd(), url) :
131
+ path.join(process.cwd(), 'public', url);
132
+ fs.readFile(filePath, (error, data) => {
124
133
  if (error) {
125
134
  return reject(error);
126
135
  }