@websolutespa/bom-mixer-image 1.0.2 → 1.0.4

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,35 @@
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.4
4
+
5
+ ### Patch Changes
6
+
7
+ - Modified: imageHandler getOriginalImage
8
+ - Updated dependencies
9
+ - @websolutespa/bom-core@1.7.5
10
+
11
+ ## 1.0.3
12
+
13
+ ### Patch Changes
14
+
15
+ - 43957d4: Fixing: production local asset public path
16
+ - Updated dependencies
17
+ - @websolutespa/bom-core@1.7.4
18
+
19
+ ## 1.0.2
20
+
21
+ ### Patch Changes
22
+
23
+ - 75b1311: Fixing: relative paths
24
+
25
+ ## 1.0.1
26
+
27
+ ### Patch Changes
28
+
29
+ - Updating: dependencies
30
+
31
+ ## 1.0.0
32
+
33
+ ### Patch Changes
34
+
35
+ - 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_config = __toESM(require("next/config"));
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 { serverRuntimeConfig } = (0, import_config.default)();
148
+ const filePath = path.join(serverRuntimeConfig.PROJECT_ROOT, "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 getConfig from "next/config";
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 { serverRuntimeConfig } = getConfig();
112
+ const filePath = path.join(serverRuntimeConfig.PROJECT_ROOT, "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.4",
4
4
  "description": "Mixer Image module of the BOM Repository",
5
5
  "keywords": [
6
6
  "bom",
@@ -24,7 +24,8 @@
24
24
  },
25
25
  "dependencies": {},
26
26
  "peerDependencies": {
27
- "next": ">= 13.4.19",
27
+ "@websolutespa/bom-core": "*",
28
+ "next": ">= 14.1.4",
28
29
  "sharp": ">= 0.30.4"
29
30
  },
30
31
  "devDependencies": {
@@ -38,7 +39,7 @@
38
39
  "sharp": "0.30.4",
39
40
  "ts-node": "^10.9.1",
40
41
  "tsup": "^6.7.0",
41
- "typescript": "^5.1.6"
42
+ "typescript": "^5.4.5"
42
43
  },
43
44
  "publishConfig": {
44
45
  "access": "public"
@@ -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 getConfig from 'next/config';
10
11
  import { apiHandler } from '../api/api.handler';
11
12
 
12
13
  const IMAGE_MAX_AGE = 604800;
@@ -45,6 +46,7 @@ export function imageHandler({ domains = [] }: { domains: string[] }) {
45
46
  const cachedName = urlToCachedName(url, width, height, quality);
46
47
  // Checking if the cached image exists
47
48
  if (fs.existsSync(cachedName)) {
49
+ // console.log('imageHandler.fromCache', cachedName);
48
50
  // Reading the cached image
49
51
  const cachedImage = await getCachedImage(cachedName);
50
52
  // Setting the 'Content-Type' header to 'image/webp'
@@ -67,8 +69,12 @@ export function imageHandler({ domains = [] }: { domains: string[] }) {
67
69
  height: height ? height : undefined,
68
70
  fit: sharp.fit.cover,
69
71
  position: sharp.strategy.entropy,
72
+ withoutEnlargement: true,
70
73
  })
71
- .webp({ quality });
74
+ .webp({
75
+ quality,
76
+ nearLossless: true,
77
+ });
72
78
  // Saving the resized image to the cache
73
79
  resizedImage.toFile(cachedName)
74
80
  .then(() => console.log('imageHandler.sharp.cached', cachedName))
@@ -120,7 +126,16 @@ function getOriginalImage(url: string, domains: string[]): Promise<Buffer> {
120
126
  });
121
127
  } else {
122
128
  // Reading the image from the file system
123
- fs.readFile(path.join(process.cwd(), 'public', url), (error, data) => {
129
+ const { serverRuntimeConfig } = getConfig();
130
+ // console.log('imageHandler.getOriginalImage.isDevelopment', isDevelopment);
131
+ const filePath = path.join(serverRuntimeConfig.PROJECT_ROOT, 'public', url);
132
+ /*
133
+ const filePath = isDevelopment ?
134
+ path.join(process.cwd(), 'public', url) :
135
+ path.join(process.cwd(), url);
136
+ */
137
+ // console.log('imageHandler.getOriginalImage.filePath', filePath);
138
+ fs.readFile(filePath, (error, data) => {
124
139
  if (error) {
125
140
  return reject(error);
126
141
  }