@websolutespa/bom-mixer-image 1.0.3 → 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 +8 -0
- package/dist/index.js +3 -3
- package/dist/index.mjs +3 -3
- package/package.json +3 -3
- package/src/image/image.handler.ts +11 -5
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -38,7 +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
|
|
41
|
+
var import_config = __toESM(require("next/config"));
|
|
42
42
|
|
|
43
43
|
// src/api/api.handler.ts
|
|
44
44
|
function apiHandler(handler) {
|
|
@@ -144,8 +144,8 @@ function getOriginalImage(url, domains) {
|
|
|
144
144
|
return reject(error);
|
|
145
145
|
});
|
|
146
146
|
} else {
|
|
147
|
-
const
|
|
148
|
-
const filePath =
|
|
147
|
+
const { serverRuntimeConfig } = (0, import_config.default)();
|
|
148
|
+
const filePath = path.join(serverRuntimeConfig.PROJECT_ROOT, "public", url);
|
|
149
149
|
fs.readFile(filePath, (error, data) => {
|
|
150
150
|
if (error) {
|
|
151
151
|
return reject(error);
|
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import * as fs from "fs";
|
|
3
3
|
import * as path from "path";
|
|
4
4
|
import sharp from "sharp";
|
|
5
|
-
import
|
|
5
|
+
import getConfig from "next/config";
|
|
6
6
|
|
|
7
7
|
// src/api/api.handler.ts
|
|
8
8
|
function apiHandler(handler) {
|
|
@@ -108,8 +108,8 @@ function getOriginalImage(url, domains) {
|
|
|
108
108
|
return reject(error);
|
|
109
109
|
});
|
|
110
110
|
} else {
|
|
111
|
-
const
|
|
112
|
-
const filePath =
|
|
111
|
+
const { serverRuntimeConfig } = getConfig();
|
|
112
|
+
const filePath = path.join(serverRuntimeConfig.PROJECT_ROOT, "public", url);
|
|
113
113
|
fs.readFile(filePath, (error, data) => {
|
|
114
114
|
if (error) {
|
|
115
115
|
return reject(error);
|
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.4",
|
|
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,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
|
|
10
|
+
import getConfig from 'next/config';
|
|
11
11
|
import { apiHandler } from '../api/api.handler';
|
|
12
12
|
|
|
13
13
|
const IMAGE_MAX_AGE = 604800;
|
|
@@ -46,6 +46,7 @@ export function imageHandler({ domains = [] }: { domains: string[] }) {
|
|
|
46
46
|
const cachedName = urlToCachedName(url, width, height, quality);
|
|
47
47
|
// Checking if the cached image exists
|
|
48
48
|
if (fs.existsSync(cachedName)) {
|
|
49
|
+
// console.log('imageHandler.fromCache', cachedName);
|
|
49
50
|
// Reading the cached image
|
|
50
51
|
const cachedImage = await getCachedImage(cachedName);
|
|
51
52
|
// Setting the 'Content-Type' header to 'image/webp'
|
|
@@ -125,10 +126,15 @@ function getOriginalImage(url: string, domains: string[]): Promise<Buffer> {
|
|
|
125
126
|
});
|
|
126
127
|
} else {
|
|
127
128
|
// Reading the image from the file system
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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);
|
|
132
138
|
fs.readFile(filePath, (error, data) => {
|
|
133
139
|
if (error) {
|
|
134
140
|
return reject(error);
|