@websolutespa/bom-mixer-image 1.0.3 → 1.0.5
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 +16 -0
- package/dist/index.js +6 -8
- package/dist/index.mjs +6 -8
- package/package.json +3 -3
- package/src/image/image.handler.ts +13 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @websolutespa/bom-mixer-image
|
|
2
2
|
|
|
3
|
+
## 1.0.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Modified: imageHandler
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @websolutespa/bom-core@1.7.6
|
|
10
|
+
|
|
11
|
+
## 1.0.4
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Modified: imageHandler getOriginalImage
|
|
16
|
+
- Updated dependencies
|
|
17
|
+
- @websolutespa/bom-core@1.7.5
|
|
18
|
+
|
|
3
19
|
## 1.0.3
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -38,7 +38,6 @@ 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");
|
|
42
41
|
|
|
43
42
|
// src/api/api.handler.ts
|
|
44
43
|
function apiHandler(handler) {
|
|
@@ -119,7 +118,7 @@ function imageHandler({ domains = [] }) {
|
|
|
119
118
|
});
|
|
120
119
|
}
|
|
121
120
|
function getOriginalImage(url, domains) {
|
|
122
|
-
return new Promise((
|
|
121
|
+
return new Promise((resolve2, reject) => {
|
|
123
122
|
if (url.indexOf("http") === 0) {
|
|
124
123
|
if (!checkUrlValidity(url, domains)) {
|
|
125
124
|
console.error("imageHandler.getOriginalImage.error invalid url");
|
|
@@ -136,7 +135,7 @@ function getOriginalImage(url, domains) {
|
|
|
136
135
|
return reject({ status: response.status, message: response.statusText });
|
|
137
136
|
}
|
|
138
137
|
response.arrayBuffer().then((buffer) => {
|
|
139
|
-
return
|
|
138
|
+
return resolve2(Buffer.from(buffer));
|
|
140
139
|
}).catch((error) => {
|
|
141
140
|
return reject(error);
|
|
142
141
|
});
|
|
@@ -144,24 +143,23 @@ function getOriginalImage(url, domains) {
|
|
|
144
143
|
return reject(error);
|
|
145
144
|
});
|
|
146
145
|
} else {
|
|
147
|
-
const
|
|
148
|
-
const filePath = isProduction ? path.join(process.cwd(), url) : path.join(process.cwd(), "public", url);
|
|
146
|
+
const filePath = path.resolve(".", "public", url);
|
|
149
147
|
fs.readFile(filePath, (error, data) => {
|
|
150
148
|
if (error) {
|
|
151
149
|
return reject(error);
|
|
152
150
|
}
|
|
153
|
-
return
|
|
151
|
+
return resolve2(data);
|
|
154
152
|
});
|
|
155
153
|
}
|
|
156
154
|
});
|
|
157
155
|
}
|
|
158
156
|
function getCachedImage(pathname) {
|
|
159
|
-
return new Promise((
|
|
157
|
+
return new Promise((resolve2, reject) => {
|
|
160
158
|
fs.readFile(pathname, (error, data) => {
|
|
161
159
|
if (error) {
|
|
162
160
|
return reject(error);
|
|
163
161
|
}
|
|
164
|
-
return
|
|
162
|
+
return resolve2(data);
|
|
165
163
|
});
|
|
166
164
|
});
|
|
167
165
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
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";
|
|
6
5
|
|
|
7
6
|
// src/api/api.handler.ts
|
|
8
7
|
function apiHandler(handler) {
|
|
@@ -83,7 +82,7 @@ function imageHandler({ domains = [] }) {
|
|
|
83
82
|
});
|
|
84
83
|
}
|
|
85
84
|
function getOriginalImage(url, domains) {
|
|
86
|
-
return new Promise((
|
|
85
|
+
return new Promise((resolve2, reject) => {
|
|
87
86
|
if (url.indexOf("http") === 0) {
|
|
88
87
|
if (!checkUrlValidity(url, domains)) {
|
|
89
88
|
console.error("imageHandler.getOriginalImage.error invalid url");
|
|
@@ -100,7 +99,7 @@ function getOriginalImage(url, domains) {
|
|
|
100
99
|
return reject({ status: response.status, message: response.statusText });
|
|
101
100
|
}
|
|
102
101
|
response.arrayBuffer().then((buffer) => {
|
|
103
|
-
return
|
|
102
|
+
return resolve2(Buffer.from(buffer));
|
|
104
103
|
}).catch((error) => {
|
|
105
104
|
return reject(error);
|
|
106
105
|
});
|
|
@@ -108,24 +107,23 @@ function getOriginalImage(url, domains) {
|
|
|
108
107
|
return reject(error);
|
|
109
108
|
});
|
|
110
109
|
} else {
|
|
111
|
-
const
|
|
112
|
-
const filePath = isProduction ? path.join(process.cwd(), url) : path.join(process.cwd(), "public", url);
|
|
110
|
+
const filePath = path.resolve(".", "public", url);
|
|
113
111
|
fs.readFile(filePath, (error, data) => {
|
|
114
112
|
if (error) {
|
|
115
113
|
return reject(error);
|
|
116
114
|
}
|
|
117
|
-
return
|
|
115
|
+
return resolve2(data);
|
|
118
116
|
});
|
|
119
117
|
}
|
|
120
118
|
});
|
|
121
119
|
}
|
|
122
120
|
function getCachedImage(pathname) {
|
|
123
|
-
return new Promise((
|
|
121
|
+
return new Promise((resolve2, reject) => {
|
|
124
122
|
fs.readFile(pathname, (error, data) => {
|
|
125
123
|
if (error) {
|
|
126
124
|
return reject(error);
|
|
127
125
|
}
|
|
128
|
-
return
|
|
126
|
+
return resolve2(data);
|
|
129
127
|
});
|
|
130
128
|
});
|
|
131
129
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@websolutespa/bom-mixer-image",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "Mixer Image module of the BOM Repository",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bom",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"dependencies": {},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"@websolutespa/bom-core": "*",
|
|
28
|
-
"next": ">=
|
|
28
|
+
"next": ">= 14.1.4",
|
|
29
29
|
"sharp": ">= 0.30.4"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"sharp": "0.30.4",
|
|
40
40
|
"ts-node": "^10.9.1",
|
|
41
41
|
"tsup": "^6.7.0",
|
|
42
|
-
"typescript": "^5.
|
|
42
|
+
"typescript": "^5.4.5"
|
|
43
43
|
},
|
|
44
44
|
"publishConfig": {
|
|
45
45
|
"access": "public"
|
|
@@ -7,7 +7,6 @@ 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';
|
|
11
10
|
import { apiHandler } from '../api/api.handler';
|
|
12
11
|
|
|
13
12
|
const IMAGE_MAX_AGE = 604800;
|
|
@@ -46,6 +45,7 @@ export function imageHandler({ domains = [] }: { domains: string[] }) {
|
|
|
46
45
|
const cachedName = urlToCachedName(url, width, height, quality);
|
|
47
46
|
// Checking if the cached image exists
|
|
48
47
|
if (fs.existsSync(cachedName)) {
|
|
48
|
+
// console.log('imageHandler.fromCache', cachedName);
|
|
49
49
|
// Reading the cached image
|
|
50
50
|
const cachedImage = await getCachedImage(cachedName);
|
|
51
51
|
// Setting the 'Content-Type' header to 'image/webp'
|
|
@@ -125,10 +125,18 @@ function getOriginalImage(url: string, domains: string[]): Promise<Buffer> {
|
|
|
125
125
|
});
|
|
126
126
|
} else {
|
|
127
127
|
// Reading the image from the file system
|
|
128
|
-
|
|
129
|
-
const filePath =
|
|
130
|
-
|
|
131
|
-
|
|
128
|
+
// console.log('imageHandler.getOriginalImage.isDevelopment', isDevelopment);
|
|
129
|
+
const filePath = path.resolve('.', 'public', url);
|
|
130
|
+
/*
|
|
131
|
+
const { serverRuntimeConfig } = getConfig();
|
|
132
|
+
const filePath = path.join(serverRuntimeConfig.PROJECT_ROOT, 'public', url);
|
|
133
|
+
*/
|
|
134
|
+
/*
|
|
135
|
+
const filePath = isDevelopment ?
|
|
136
|
+
path.join(process.cwd(), 'public', url) :
|
|
137
|
+
path.join(process.cwd(), url);
|
|
138
|
+
*/
|
|
139
|
+
// console.log('imageHandler.getOriginalImage.filePath', filePath);
|
|
132
140
|
fs.readFile(filePath, (error, data) => {
|
|
133
141
|
if (error) {
|
|
134
142
|
return reject(error);
|