@nyris/nyris-webapp 0.3.65 → 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/build/asset-manifest.json +3 -3
- package/build/index.html +1 -1
- package/build/static/js/{main.1bd28035.js → main.8a96a7fa.js} +3 -3
- package/build/static/js/{main.1bd28035.js.map → main.8a96a7fa.js.map} +1 -1
- package/package.json +3 -3
- package/src/components/ImagePreview.tsx +1 -0
- package/src/hooks/useImageSearch.ts +11 -5
- package/src/page/result/index.tsx +7 -2
- package/src/utils.ts +23 -11
- /package/build/static/js/{main.1bd28035.js.LICENSE.txt → main.8a96a7fa.js.LICENSE.txt} +0 -0
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nyris/nyris-webapp",
|
|
3
|
-
"version": "0.3.
|
|
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.
|
|
11
|
-
"@nyris/nyris-react-components": "^0.3.
|
|
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",
|
|
@@ -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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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(
|
|
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:
|
|
98
|
+
image: requestImage,
|
|
93
99
|
settings,
|
|
94
100
|
filters: !isEmpty(preFilter) ? preFilterValues : undefined,
|
|
95
101
|
region,
|
|
@@ -152,7 +152,12 @@ function ResultComponent(props: Props) {
|
|
|
152
152
|
}
|
|
153
153
|
dispatch(loadingActionResults());
|
|
154
154
|
|
|
155
|
-
singleImageSearch({
|
|
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 = (
|
|
45
|
-
let blob:
|
|
44
|
+
export const compressImage = async (input: string | Blob): Promise<string> => {
|
|
45
|
+
let blob: Blob;
|
|
46
46
|
|
|
47
|
-
if (typeof
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
66
|
+
} else {
|
|
67
|
+
blob = input;
|
|
56
68
|
}
|
|
57
69
|
|
|
58
70
|
return new Promise<string>((resolve, reject) => {
|
|
59
|
-
new Compressor(blob
|
|
71
|
+
new Compressor(blob, {
|
|
60
72
|
quality: 0.91,
|
|
61
73
|
maxHeight: 1024,
|
|
62
74
|
maxWidth: 1024,
|
|
File without changes
|