@websolutespa/bom-mixer-image 1.0.6 → 1.0.7

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.7
4
+
5
+ ### Patch Changes
6
+
7
+ - Fixing: imageHandler Vercel support
8
+ - Updated dependencies
9
+ - @websolutespa/bom-core@1.7.7
10
+
3
11
  ## 1.0.6
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_bom_core = require("@websolutespa/bom-core");
42
41
 
43
42
  // src/api/api.handler.ts
44
43
  function apiHandler(handler) {
@@ -95,6 +94,9 @@ function imageHandler({ domains = [] }) {
95
94
  response.setHeader("Cache-Control", `public, max-age=${IMAGE_MAX_AGE}`);
96
95
  return response.send(cachedImage);
97
96
  }
97
+ if (url.indexOf("http") === -1 && isVercel()) {
98
+ response.redirect(307, url);
99
+ }
98
100
  const originalImage = await getOriginalImage(url, domains, request.headers);
99
101
  if (originalImage) {
100
102
  const resizedImage = (0, import_sharp.default)(originalImage).resize({
@@ -145,17 +147,12 @@ function getOriginalImage(url, domains, headers, skipUrlValidity = false) {
145
147
  });
146
148
  } else {
147
149
  const filePath = path.join(process.cwd(), "public", url);
148
- if (fs.existsSync(filePath)) {
149
- fs.readFile(filePath, (error, data) => {
150
- if (error) {
151
- return reject(error);
152
- }
153
- return resolve(data);
154
- });
155
- } else {
156
- const origin = (0, import_bom_core.getOrigin)(headers);
157
- return getOriginalImage(`${origin}${url}`, domains, headers, true);
158
- }
150
+ fs.readFile(filePath, (error, data) => {
151
+ if (error) {
152
+ return reject(error);
153
+ }
154
+ return resolve(data);
155
+ });
159
156
  }
160
157
  });
161
158
  }
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 { getOrigin } from "@websolutespa/bom-core";
6
5
 
7
6
  // src/api/api.handler.ts
8
7
  function apiHandler(handler) {
@@ -59,6 +58,9 @@ function imageHandler({ domains = [] }) {
59
58
  response.setHeader("Cache-Control", `public, max-age=${IMAGE_MAX_AGE}`);
60
59
  return response.send(cachedImage);
61
60
  }
61
+ if (url.indexOf("http") === -1 && isVercel()) {
62
+ response.redirect(307, url);
63
+ }
62
64
  const originalImage = await getOriginalImage(url, domains, request.headers);
63
65
  if (originalImage) {
64
66
  const resizedImage = sharp(originalImage).resize({
@@ -109,17 +111,12 @@ function getOriginalImage(url, domains, headers, skipUrlValidity = false) {
109
111
  });
110
112
  } else {
111
113
  const filePath = path.join(process.cwd(), "public", url);
112
- if (fs.existsSync(filePath)) {
113
- fs.readFile(filePath, (error, data) => {
114
- if (error) {
115
- return reject(error);
116
- }
117
- return resolve(data);
118
- });
119
- } else {
120
- const origin = getOrigin(headers);
121
- return getOriginalImage(`${origin}${url}`, domains, headers, true);
122
- }
114
+ fs.readFile(filePath, (error, data) => {
115
+ if (error) {
116
+ return reject(error);
117
+ }
118
+ return resolve(data);
119
+ });
123
120
  }
124
121
  });
125
122
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@websolutespa/bom-mixer-image",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "Mixer Image module of the BOM Repository",
5
5
  "keywords": [
6
6
  "bom",
@@ -8,7 +8,6 @@ import * as path from 'path';
8
8
  // Importing 'sharp' for image processing
9
9
  import sharp from 'sharp';
10
10
  // Importing 'apiHandler' from '../api/api.handler'
11
- import { getOrigin } from '@websolutespa/bom-core';
12
11
  import { apiHandler } from '../api/api.handler';
13
12
 
14
13
  const IMAGE_MAX_AGE = 604800;
@@ -59,6 +58,10 @@ export function imageHandler({ domains = [] }: { domains: string[] }) {
59
58
  // Ending the response and sending the cached image
60
59
  return response.send(cachedImage);
61
60
  }
61
+ // Temporarily fix Vercel local image issue
62
+ if (url.indexOf('http') === -1 && isVercel()) {
63
+ response.redirect(307, url);
64
+ }
62
65
  // Reading the original image
63
66
  const originalImage = await getOriginalImage(url, domains, request.headers);
64
67
  // Checking if the original image exists
@@ -130,18 +133,16 @@ function getOriginalImage(url: string, domains: string[], headers: IncomingHttpH
130
133
  });
131
134
  } else {
132
135
  // Reading the image from the file system
133
- // console.log('imageHandler.getOriginalImage.isDevelopment', isDevelopment);
134
136
  const filePath = path.join(process.cwd(), 'public', url);
135
- /*
136
- const { serverRuntimeConfig } = getConfig();
137
- const filePath = path.join(serverRuntimeConfig.PROJECT_ROOT, 'public', url);
138
- */
139
- /*
140
- const filePath = isDevelopment ?
141
- path.join(process.cwd(), 'public', url) :
142
- path.join(process.cwd(), url);
143
- */
144
137
  // console.log('imageHandler.getOriginalImage.filePath', filePath);
138
+ fs.readFile(filePath, (error, data) => {
139
+ if (error) {
140
+ return reject(error);
141
+ }
142
+ // Resolving the promise with the image data
143
+ return resolve(data);
144
+ });
145
+ /*
145
146
  // Check if the file exists
146
147
  if (fs.existsSync(filePath)) {
147
148
  fs.readFile(filePath, (error, data) => {
@@ -155,14 +156,6 @@ function getOriginalImage(url: string, domains: string[], headers: IncomingHttpH
155
156
  const origin = getOrigin(headers);
156
157
  return getOriginalImage(`${origin}${url}`, domains, headers, true);
157
158
  }
158
- /*
159
- fs.readFile(filePath, (error, data) => {
160
- if (error) {
161
- return reject(error);
162
- }
163
- // Resolving the promise with the image data
164
- return resolve(data);
165
- });
166
159
  */
167
160
  }
168
161
  });