@nyris/nyris-webapp 0.3.3 → 0.3.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/build/asset-manifest.json +8 -8
- package/build/index.html +1 -1
- package/build/{precache-manifest.01ce682577e62add75aa397b2a944b75.js → precache-manifest.9800bdc87f5a2c5d6d8a5d1a5287598f.js} +9 -9
- package/build/service-worker.js +1 -1
- package/build/static/js/2.29ddd567.chunk.js +3 -0
- package/build/static/js/{2.d1562c08.chunk.js.LICENSE.txt → 2.29ddd567.chunk.js.LICENSE.txt} +0 -9
- package/build/static/js/2.29ddd567.chunk.js.map +1 -0
- package/build/static/js/main.c35ded37.chunk.js +2 -0
- package/build/static/js/main.c35ded37.chunk.js.map +1 -0
- package/package.json +3 -3
- package/src/App.tsx +3 -6
- package/src/Store/Nyris.ts +7 -7
- package/src/Store/Search.ts +11 -10
- package/src/Store/Store.ts +12 -5
- package/src/components/DragDropFile.tsx +9 -9
- package/src/components/Feedback.tsx +2 -2
- package/src/components/Footer.tsx +1 -1
- package/src/components/HeaderMd.tsx +4 -5
- package/src/index.tsx +2 -1
- package/src/modules/LandingPage/{indexApp.tsx → App.tsx} +53 -227
- package/src/modules/LandingPage/{indexAppMD.tsx → AppMD.tsx} +49 -151
- package/src/modules/LandingPage/index.tsx +193 -0
- package/src/modules/LandingPage/indexNewVersion.tsx +7 -14
- package/src/modules/LandingPage/propsType.ts +43 -0
- package/src/page/result/index.tsx +11 -16
- package/src/services/findRegionsCustom.ts +0 -197
- package/src/services/image.ts +11 -14
- package/src/services/session.ts +6 -6
- package/src/services/types.ts +1 -15
- package/src/types.ts +0 -1
- package/build/static/js/2.d1562c08.chunk.js +0 -3
- package/build/static/js/2.d1562c08.chunk.js.map +0 -1
- package/build/static/js/main.5c08aba4.chunk.js +0 -2
- package/build/static/js/main.5c08aba4.chunk.js.map +0 -1
- package/src/App.test.tsx +0 -49
- package/src/Store/epics/feedback.ts +0 -59
- package/src/Store/epics/types.ts +0 -12
- package/src/components/preview/preview.tsx +0 -433
|
@@ -13,200 +13,3 @@ import {
|
|
|
13
13
|
toCanvas,
|
|
14
14
|
} from "./nyris";
|
|
15
15
|
|
|
16
|
-
export interface RegionData {
|
|
17
|
-
rect: {
|
|
18
|
-
x: number;
|
|
19
|
-
y: number;
|
|
20
|
-
w: number;
|
|
21
|
-
h: number;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
interface SearchResult {
|
|
26
|
-
results: Result[];
|
|
27
|
-
requestId: string;
|
|
28
|
-
categoryPredictions: any[];
|
|
29
|
-
codes: any[];
|
|
30
|
-
duration: number;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export default class NyrisAPICT {
|
|
34
|
-
private readonly httpClient: AxiosInstance;
|
|
35
|
-
private readonly imageMatchingUrl: string;
|
|
36
|
-
private readonly regionProposalUrl: string;
|
|
37
|
-
private readonly responseFormat: string;
|
|
38
|
-
private imageMatchingUrlBySku: string;
|
|
39
|
-
private imageMatchingSubmitManualUrl: string;
|
|
40
|
-
private feedbackUrl: string;
|
|
41
|
-
|
|
42
|
-
constructor(private settings: SearchServiceSettings) {
|
|
43
|
-
this.httpClient = axios.create();
|
|
44
|
-
this.imageMatchingUrl =
|
|
45
|
-
this.settings.imageMatchingUrl || "https://api.nyris.io/find/v1";
|
|
46
|
-
this.imageMatchingUrlBySku =
|
|
47
|
-
this.settings.imageMatchingUrlBySku ||
|
|
48
|
-
"https://api.nyris.io/recommend/v1/";
|
|
49
|
-
this.imageMatchingSubmitManualUrl =
|
|
50
|
-
this.settings.imageMatchingSubmitManualUrl ||
|
|
51
|
-
"https://api.nyris.io/find/v1/manual/";
|
|
52
|
-
this.feedbackUrl =
|
|
53
|
-
this.settings.feedbackUrl || "https://api.nyris.io/feedback/v1/";
|
|
54
|
-
this.regionProposalUrl =
|
|
55
|
-
this.settings.regionProposalUrl ||
|
|
56
|
-
"https://api.nyris.io/find/v1/regions/";
|
|
57
|
-
this.responseFormat =
|
|
58
|
-
this.settings.responseFormat || "application/offers.nyris+json";
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Find significant sections in the image.
|
|
63
|
-
* @param canvas Canvas, video or image to search with.
|
|
64
|
-
* @param options See [[ImageSearchOptions]].
|
|
65
|
-
* @returns A list of regions, see [[Region]].
|
|
66
|
-
*/
|
|
67
|
-
async findRegions(
|
|
68
|
-
canvas: HTMLCanvasElement | HTMLVideoElement | HTMLImageElement,
|
|
69
|
-
options: ImageSearchOptions
|
|
70
|
-
): Promise<Region[]> {
|
|
71
|
-
let [origW, origH] = getElementSize(canvas);
|
|
72
|
-
let { w: scaledW, h: scaledH } = getThumbSizeArea(
|
|
73
|
-
options.maxWidth,
|
|
74
|
-
options.maxHeight,
|
|
75
|
-
origW,
|
|
76
|
-
origH
|
|
77
|
-
);
|
|
78
|
-
let resizedCroppedCanvas = toCanvas(canvas, { w: scaledW, h: scaledH });
|
|
79
|
-
let blob = await canvasToJpgBlob(resizedCroppedCanvas, options.jpegQuality);
|
|
80
|
-
|
|
81
|
-
const headers = {
|
|
82
|
-
"Content-Type": "image/jpeg",
|
|
83
|
-
"X-Api-Key": this.settings.apiKey,
|
|
84
|
-
};
|
|
85
|
-
let response = await this.httpClient.request<any[]>({
|
|
86
|
-
method: "POST",
|
|
87
|
-
url: this.regionProposalUrl,
|
|
88
|
-
data: blob,
|
|
89
|
-
headers,
|
|
90
|
-
});
|
|
91
|
-
let regions: any[] = response.data;
|
|
92
|
-
return regions.map((r) => ({
|
|
93
|
-
className: r.className,
|
|
94
|
-
confidence: r.confidence,
|
|
95
|
-
x1: r.region.left / scaledW,
|
|
96
|
-
x2: r.region.right / scaledW,
|
|
97
|
-
y1: r.region.top / scaledH,
|
|
98
|
-
y2: r.region.bottom / scaledH,
|
|
99
|
-
}));
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
private async prepareImage(
|
|
103
|
-
canvas: HTMLCanvasElement | HTMLImageElement | HTMLVideoElement,
|
|
104
|
-
options: ImageSearchOptions
|
|
105
|
-
): Promise<{ bytes: Blob; region?: RegionData }> {
|
|
106
|
-
let [w, h] = getElementSize(canvas);
|
|
107
|
-
let crop = options.crop
|
|
108
|
-
? options.crop
|
|
109
|
-
: {
|
|
110
|
-
x: 0,
|
|
111
|
-
y: 0,
|
|
112
|
-
w: w,
|
|
113
|
-
h: h,
|
|
114
|
-
};
|
|
115
|
-
let region: RegionData | undefined = undefined;
|
|
116
|
-
if (options.crop) {
|
|
117
|
-
region = {
|
|
118
|
-
rect: {
|
|
119
|
-
w: Math.min(1, crop.w / w),
|
|
120
|
-
h: Math.min(1, crop.h / h),
|
|
121
|
-
x: Math.min(1, crop.x / w),
|
|
122
|
-
y: Math.min(1, crop.y / h),
|
|
123
|
-
},
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
let scaledSize = getThumbSizeArea(
|
|
127
|
-
options.maxWidth,
|
|
128
|
-
options.maxHeight,
|
|
129
|
-
crop.w,
|
|
130
|
-
crop.h
|
|
131
|
-
);
|
|
132
|
-
let resizedCroppedCanvas = toCanvas(canvas, scaledSize, undefined, crop);
|
|
133
|
-
let bytes = await canvasToJpgBlob(
|
|
134
|
-
resizedCroppedCanvas,
|
|
135
|
-
options.jpegQuality
|
|
136
|
-
);
|
|
137
|
-
|
|
138
|
-
return { bytes, region };
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
async findByImage(
|
|
142
|
-
canvas: HTMLCanvasElement | HTMLImageElement | HTMLVideoElement,
|
|
143
|
-
options: ImageSearchOptions
|
|
144
|
-
): Promise<SearchResult> {
|
|
145
|
-
const image = await this.prepareImage(canvas, options);
|
|
146
|
-
|
|
147
|
-
if (this.settings.customSearchRequest)
|
|
148
|
-
return this.settings.customSearchRequest(image.bytes, this.httpClient); // TODO check if the interface is ok for hooks
|
|
149
|
-
|
|
150
|
-
let headers: any = {
|
|
151
|
-
"Content-Type": "image/jpeg",
|
|
152
|
-
"X-Api-Key": this.settings.apiKey,
|
|
153
|
-
"Accept-Language": "de,*;q=0.5",
|
|
154
|
-
Accept: this.responseFormat,
|
|
155
|
-
};
|
|
156
|
-
const xOptions = [];
|
|
157
|
-
if (this.settings.xOptions) xOptions.push(this.settings.xOptions as string);
|
|
158
|
-
if (options.useRecommendations) xOptions.push("+recommendations");
|
|
159
|
-
if (xOptions.length > 0) headers["X-Options"] = xOptions.join(" ");
|
|
160
|
-
let params = options.geoLocation
|
|
161
|
-
? {
|
|
162
|
-
lat: options.geoLocation.lat.toString(),
|
|
163
|
-
lon: options.geoLocation.lon.toString(),
|
|
164
|
-
dist: options.geoLocation.dist.toString(),
|
|
165
|
-
}
|
|
166
|
-
: {};
|
|
167
|
-
// console.log("p", params, image.bytes);
|
|
168
|
-
let res: any = await this.httpClient.request<any>({
|
|
169
|
-
method: "POST",
|
|
170
|
-
url: this.imageMatchingUrl,
|
|
171
|
-
data: image.bytes,
|
|
172
|
-
params,
|
|
173
|
-
headers,
|
|
174
|
-
responseType: "json",
|
|
175
|
-
});
|
|
176
|
-
// console.log(res);
|
|
177
|
-
const categoryPredictions = Object.entries(
|
|
178
|
-
res.data.predicted_category || {}
|
|
179
|
-
)
|
|
180
|
-
.map(([name, score]) => ({
|
|
181
|
-
name: name,
|
|
182
|
-
score: score as number,
|
|
183
|
-
}))
|
|
184
|
-
.sort((a, b) => b.score - a.score);
|
|
185
|
-
let codes = res.data.barcodes || [];
|
|
186
|
-
|
|
187
|
-
let responseData = this.settings.responseHook
|
|
188
|
-
? this.settings.responseHook(res.data)
|
|
189
|
-
: res.data;
|
|
190
|
-
|
|
191
|
-
let results: Result[] = responseData?.results.map(
|
|
192
|
-
(r: Result, i: number) => ({
|
|
193
|
-
...r,
|
|
194
|
-
position: i,
|
|
195
|
-
})
|
|
196
|
-
);
|
|
197
|
-
const requestId = res.headers["x-matching-request"];
|
|
198
|
-
const duration = res.data.durationSeconds;
|
|
199
|
-
return { results, requestId, duration, categoryPredictions, codes };
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
async createSession(): Promise<{ data: any }> {
|
|
203
|
-
let headers: any = {
|
|
204
|
-
"X-Api-Key": this.settings.apiKey,
|
|
205
|
-
};
|
|
206
|
-
return await this.httpClient.request({
|
|
207
|
-
method: "POST",
|
|
208
|
-
url: `${this.imageMatchingUrl}/session`,
|
|
209
|
-
headers,
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
}
|
package/src/services/image.ts
CHANGED
|
@@ -1,27 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import NyrisAPICT from "./findRegionsCustom";
|
|
1
|
+
import {ImageSearchOptions, NyrisAPISettings, selectFirstCenteredRegion, urlOrBlobToCanvas} from "@nyris/nyris-api";
|
|
3
2
|
import NyrisAPI from "@nyris/nyris-api";
|
|
4
3
|
import { fileOrBlobToCanvas, rectToCrop } from "./nyris";
|
|
5
4
|
|
|
6
|
-
export const serviceImage = async (file: any,
|
|
5
|
+
export const serviceImage = async (file: any, settings: NyrisAPISettings) => {
|
|
7
6
|
try {
|
|
8
|
-
const
|
|
9
|
-
let options = settings;
|
|
10
|
-
const nyrisApi = new NyrisAPICT(settings);
|
|
7
|
+
const nyrisApi = new NyrisAPI(settings);
|
|
11
8
|
const randomId = Math.random().toString();
|
|
12
9
|
|
|
13
|
-
const image
|
|
10
|
+
const image = await fileOrBlobToCanvas(file);
|
|
14
11
|
const imageFileCanvas = { canvas: image, id: randomId };
|
|
15
12
|
|
|
16
|
-
const
|
|
13
|
+
const regions = await nyrisApi.findRegions(image);
|
|
14
|
+
const searchRegion = selectFirstCenteredRegion(regions, 0.3, {x1: 0, x2: 1, y1: 0, y2: 1});
|
|
15
|
+
|
|
16
|
+
let options : ImageSearchOptions = {
|
|
17
17
|
...settings,
|
|
18
|
-
|
|
18
|
+
cropRect: searchRegion
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
const regions: any = await nyrisApi.findRegions(
|
|
22
|
-
image,
|
|
23
|
-
searchServiceSettings
|
|
24
|
-
);
|
|
25
21
|
const { results, requestId, duration, categoryPredictions, codes } =
|
|
26
22
|
await nyrisApi.findByImage(image, options);
|
|
27
23
|
const payload = {
|
|
@@ -32,6 +28,7 @@ export const serviceImage = async (file: any, stateStore: any) => {
|
|
|
32
28
|
duration,
|
|
33
29
|
regions,
|
|
34
30
|
requestImage: imageFileCanvas,
|
|
31
|
+
selectedRegion: searchRegion
|
|
35
32
|
};
|
|
36
33
|
|
|
37
34
|
return payload;
|
|
@@ -79,7 +76,7 @@ export const searchImageByPosition = async (
|
|
|
79
76
|
const { settings } = stateStore;
|
|
80
77
|
|
|
81
78
|
let options = settings;
|
|
82
|
-
const nyrisApi = new
|
|
79
|
+
const nyrisApi = new NyrisAPI(settings);
|
|
83
80
|
if (region) {
|
|
84
81
|
let { x1, x2, y1, y2 } = region;
|
|
85
82
|
let crop = rectToCrop({
|
package/src/services/session.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import {NyrisAPISettings} from "@nyris/nyris-api";
|
|
3
3
|
|
|
4
4
|
const httpClient = axios.create();
|
|
5
5
|
|
|
6
|
-
export const createSessionByApi = async (
|
|
7
|
-
const {
|
|
6
|
+
export const createSessionByApi = async (settings: NyrisAPISettings) => {
|
|
7
|
+
const { apiKey, baseUrl} = settings;
|
|
8
8
|
try {
|
|
9
9
|
let headers: any = {
|
|
10
|
-
"X-Api-Key":
|
|
10
|
+
"X-Api-Key": apiKey,
|
|
11
11
|
};
|
|
12
12
|
return await httpClient.request({
|
|
13
13
|
method: "POST",
|
|
14
|
-
url: `${
|
|
14
|
+
url: `${baseUrl}/find/v1/session`,
|
|
15
15
|
headers,
|
|
16
16
|
});
|
|
17
17
|
} catch (error: any) {
|
package/src/services/types.ts
CHANGED
|
@@ -1,22 +1,8 @@
|
|
|
1
1
|
// import {SearchAction, SearchState} from "./actions/searchActions";
|
|
2
2
|
// import {NyrisAction, NyrisAppState} from "./actions/nyrisAppActions";
|
|
3
3
|
|
|
4
|
-
export interface MDSettings {
|
|
5
|
-
customFontFamily?: string,
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
appBarTitle: string,
|
|
9
|
-
appBarCustomBackgroundColor?: string,
|
|
10
|
-
appBarCustomTextColor?: string,
|
|
11
|
-
|
|
12
|
-
primaryColor: string,
|
|
13
|
-
secondaryColor: string,
|
|
14
|
-
resultFirstRowProperty: string,
|
|
15
|
-
resultSecondRowProperty: string,
|
|
16
|
-
|
|
17
|
-
resultLinkText?: string,
|
|
18
|
-
resultLinkIcon?: string,
|
|
19
|
-
}
|
|
5
|
+
import {MDSettings} from "../types";
|
|
20
6
|
|
|
21
7
|
export interface SearchServiceSettings {
|
|
22
8
|
xOptions: boolean | string,
|