@nyris/nyris-webapp 0.3.64 → 0.3.66

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/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@nyris/nyris-webapp",
3
- "version": "0.3.64",
3
+ "version": "0.3.66",
4
4
  "dependencies": {
5
5
  "@auth0/auth0-react": "^2.2.4",
6
6
  "@emailjs/browser": "^4.3.3",
7
7
  "@material-ui/core": "^4.12.4",
8
8
  "@material-ui/icons": "^4.11.3",
9
9
  "@material-ui/lab": "^4.0.0-alpha.61",
10
- "@nyris/nyris-api": "^0.3.64",
11
- "@nyris/nyris-react-components": "^0.3.64",
10
+ "@nyris/nyris-api": "^0.3.66",
11
+ "@nyris/nyris-react-components": "^0.3.66",
12
12
  "@reduxjs/toolkit": "^2.2.1",
13
13
  "@splidejs/react-splide": "^0.7.12",
14
14
  "@testing-library/jest-dom": "^5.17.0",
@@ -78,7 +78,6 @@ var settings = {
78
78
  experienceVisualSearch: false,
79
79
  experienceVisualSearchImages: [],
80
80
  simpleCardView: false,
81
- clarityId: '',
82
81
  noSimilarSearch: false,
83
82
  showFeedback: false,
84
83
  rfq: {
@@ -12,6 +12,7 @@ settings.algolia.enabled = true;
12
12
  settings.preview = true;
13
13
  settings.showFeedbackAndShare = false;
14
14
  settings.multiImageSearch = false;
15
+ settings.clarityId = '';
15
16
 
16
17
  if (settings.rfq?.enabled && settings.support?.enabled) {
17
18
  settings.support.enabled = false;
@@ -180,6 +180,7 @@ function ImagePreviewComponent({
180
180
  settings,
181
181
  imageRegion: r,
182
182
  showFeedback: true,
183
+ compress: false,
183
184
  }).then((res: any) => {
184
185
  dispatch(updateStatusLoading(false));
185
186
 
@@ -46,23 +46,29 @@ export const useImageSearch = () => {
46
46
  showFeedback = true,
47
47
  imageRegion,
48
48
  newSearch,
49
+ compress = true,
49
50
  }: {
50
51
  image: any;
51
52
  settings: AppSettings;
52
53
  showFeedback?: boolean;
53
54
  imageRegion?: RectCoords;
54
55
  newSearch?: boolean;
56
+ compress?: boolean;
55
57
  }) => {
56
58
  let region: RectCoords | undefined = imageRegion;
57
59
  let res: any;
58
60
  let compressedBase64;
59
61
 
60
- try {
61
- compressedBase64 = await compressImage(image);
62
- } catch (error) {}
62
+ if (compress) {
63
+ try {
64
+ compressedBase64 = await compressImage(image);
65
+ } catch (error) {}
66
+ }
63
67
 
64
68
  let canvasImage = await createImage(compressedBase64 || image);
65
69
 
70
+ let requestImage = await createImage(image);
71
+
66
72
  if (!imageRegion) {
67
73
  dispatch(setRequestImage(canvasImage));
68
74
  setRequestImages([canvasImage]);
@@ -70,7 +76,7 @@ export const useImageSearch = () => {
70
76
 
71
77
  if (regions && !imageRegion) {
72
78
  try {
73
- let res = await findRegions(canvasImage, settings);
79
+ let res = await findRegions(requestImage, settings);
74
80
  setDetectedObject(res.regions, 0);
75
81
  dispatch(setRegions(res.regions));
76
82
  region = res.selectedRegion;
@@ -89,7 +95,7 @@ export const useImageSearch = () => {
89
95
 
90
96
  try {
91
97
  res = await find({
92
- image: canvasImage,
98
+ image: requestImage,
93
99
  settings,
94
100
  filters: !isEmpty(preFilter) ? preFilterValues : undefined,
95
101
  region,
@@ -1,42 +1,42 @@
1
+ import React from 'react';
1
2
  import 'react-app-polyfill/ie11';
2
3
  import 'react-app-polyfill/stable';
3
- import React, { useEffect } from 'react';
4
4
  import 'typeface-roboto';
5
5
  import 'index.css';
6
6
 
7
7
  import AppMD from 'page/landingPage/HomeDesktop';
8
8
  import AppMobile from 'page/landingPage/HomeMobile';
9
- import { useAppSelector } from 'Store/Store';
9
+ // import { useAppSelector } from 'Store/Store';
10
10
 
11
11
  function Home(): JSX.Element {
12
- const clarityId = useAppSelector(state => state.settings.clarityId);
12
+ // const clarityId = useAppSelector(state => state.settings.clarityId);
13
13
 
14
- useEffect(() => {
15
- if (clarityId) {
16
- clarify(window, document, 'clarity', 'script', clarityId);
17
- }
18
- }, [clarityId]);
14
+ // useEffect(() => {
15
+ // if (clarityId) {
16
+ // clarify(window, document, 'clarity', 'script', clarityId);
17
+ // }
18
+ // }, [clarityId]);
19
19
 
20
- const clarify = function (
21
- c: any,
22
- l: Document,
23
- a: string,
24
- r: string,
25
- i: string,
26
- ) {
27
- c[a] =
28
- c[a] ||
29
- function () {
30
- (c[a].q = c[a].q || []).push(arguments);
31
- };
32
- const t: any = l.createElement(r);
33
- t.async = true;
34
- t.src = `https://www.clarity.ms/tag/${i}`;
35
- const y = l.getElementsByTagName(r)[0];
36
- if (y.parentNode) {
37
- y.parentNode.insertBefore(t, y);
38
- }
39
- };
20
+ // const clarify = function (
21
+ // c: any,
22
+ // l: Document,
23
+ // a: string,
24
+ // r: string,
25
+ // i: string,
26
+ // ) {
27
+ // c[a] =
28
+ // c[a] ||
29
+ // function () {
30
+ // (c[a].q = c[a].q || []).push(arguments);
31
+ // };
32
+ // const t: any = l.createElement(r);
33
+ // t.async = true;
34
+ // t.src = `https://www.clarity.ms/tag/${i}`;
35
+ // const y = l.getElementsByTagName(r)[0];
36
+ // if (y.parentNode) {
37
+ // y.parentNode.insertBefore(t, y);
38
+ // }
39
+ // };
40
40
 
41
41
  return (
42
42
  <>
@@ -152,7 +152,12 @@ function ResultComponent(props: Props) {
152
152
  }
153
153
  dispatch(loadingActionResults());
154
154
 
155
- singleImageSearch({ image: url, settings, showFeedback: true }).then(() => {
155
+ singleImageSearch({
156
+ image: url,
157
+ settings,
158
+ showFeedback: true,
159
+ compress: false,
160
+ }).then(() => {
156
161
  dispatch(updateStatusLoading(false));
157
162
  });
158
163
  };
@@ -189,12 +194,12 @@ function ResultComponent(props: Props) {
189
194
  }
190
195
  dispatch(updateStatusLoading(true));
191
196
  dispatch(loadingActionResults());
192
-
193
197
  if (requestImages.length === 1) {
194
198
  singleImageSearch({
195
199
  image: requestImages[0],
196
200
  settings,
197
201
  imageRegion: imageRegions[0],
202
+ compress: false,
198
203
  }).then(res => {
199
204
  dispatch(updateStatusLoading(false));
200
205
  });
package/src/utils.ts CHANGED
@@ -41,22 +41,34 @@ export function getThumbSizeLongestEdge(
41
41
  };
42
42
  }
43
43
 
44
- export const compressImage = (blobOrImage: any) => {
45
- let blob: any;
44
+ export const compressImage = async (input: string | Blob): Promise<string> => {
45
+ let blob: Blob;
46
46
 
47
- if (typeof blobOrImage === 'string' && !blobOrImage.startsWith('https:')) {
48
- const byteString = atob(blobOrImage.split(',')[1]);
49
- const mimeString = blobOrImage.split(',')[0].split(':')[1].split(';')[0];
50
- const ab = new ArrayBuffer(byteString.length);
51
- const ia = new Uint8Array(ab);
52
- for (let i = 0; i < byteString.length; i++) {
53
- ia[i] = byteString.charCodeAt(i);
47
+ if (typeof input === 'string') {
48
+ if (input.startsWith('https:')) {
49
+ // Fetch the image from the URL and convert it to a Blob
50
+ const response = await fetch(input);
51
+ if (!response.ok) {
52
+ throw new Error(`Failed to fetch image: ${response.statusText}`);
53
+ }
54
+ blob = await response.blob();
55
+ } else {
56
+ // Convert base64 string to Blob
57
+ const byteString = atob(input.split(',')[1]);
58
+ const mimeString = input.split(',')[0].split(':')[1].split(';')[0];
59
+ const ab = new ArrayBuffer(byteString.length);
60
+ const ia = new Uint8Array(ab);
61
+ for (let i = 0; i < byteString.length; i++) {
62
+ ia[i] = byteString.charCodeAt(i);
63
+ }
64
+ blob = new Blob([ab], { type: mimeString });
54
65
  }
55
- blob = new Blob([ab], { type: mimeString });
66
+ } else {
67
+ blob = input;
56
68
  }
57
69
 
58
70
  return new Promise<string>((resolve, reject) => {
59
- new Compressor(blob || blobOrImage, {
71
+ new Compressor(blob, {
60
72
  quality: 0.91,
61
73
  maxHeight: 1024,
62
74
  maxWidth: 1024,