@websolutespa/bom-mixer-image 1.0.4 → 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 CHANGED
@@ -1,5 +1,13 @@
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
+
3
11
  ## 1.0.4
4
12
 
5
13
  ### 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_config = __toESM(require("next/config"));
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((resolve, reject) => {
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 resolve(Buffer.from(buffer));
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 { serverRuntimeConfig } = (0, import_config.default)();
148
- const filePath = path.join(serverRuntimeConfig.PROJECT_ROOT, "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 resolve(data);
151
+ return resolve2(data);
154
152
  });
155
153
  }
156
154
  });
157
155
  }
158
156
  function getCachedImage(pathname) {
159
- return new Promise((resolve, reject) => {
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 resolve(data);
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 getConfig from "next/config";
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((resolve, reject) => {
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 resolve(Buffer.from(buffer));
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 { serverRuntimeConfig } = getConfig();
112
- const filePath = path.join(serverRuntimeConfig.PROJECT_ROOT, "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 resolve(data);
115
+ return resolve2(data);
118
116
  });
119
117
  }
120
118
  });
121
119
  }
122
120
  function getCachedImage(pathname) {
123
- return new Promise((resolve, reject) => {
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 resolve(data);
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.4",
3
+ "version": "1.0.5",
4
4
  "description": "Mixer Image module of the BOM Repository",
5
5
  "keywords": [
6
6
  "bom",
@@ -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 getConfig from 'next/config';
11
10
  import { apiHandler } from '../api/api.handler';
12
11
 
13
12
  const IMAGE_MAX_AGE = 604800;
@@ -126,9 +125,12 @@ function getOriginalImage(url: string, domains: string[]): Promise<Buffer> {
126
125
  });
127
126
  } else {
128
127
  // Reading the image from the file system
129
- const { serverRuntimeConfig } = getConfig();
130
128
  // console.log('imageHandler.getOriginalImage.isDevelopment', isDevelopment);
129
+ const filePath = path.resolve('.', 'public', url);
130
+ /*
131
+ const { serverRuntimeConfig } = getConfig();
131
132
  const filePath = path.join(serverRuntimeConfig.PROJECT_ROOT, 'public', url);
133
+ */
132
134
  /*
133
135
  const filePath = isDevelopment ?
134
136
  path.join(process.cwd(), 'public', url) :