-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfingerprint.js
58 lines (53 loc) · 1.51 KB
/
fingerprint.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const captureBtn = document.getElementById("captureBtn");
const deviceBtn = document.getElementById("deviceBtn");
const BASE_URL = "http://localhost:8282";
const captureUrl = "/v2/scanner/capture";
const deviceUrl = "/v2/scanner/devices";
captureBtn.addEventListener("click", () => {
const requestBody = {
formatFmd: "ISO_19794_2_2005",
formatFid: "ISO_19794_4_2005",
};
sendCaptureRequest(BASE_URL + captureUrl, requestBody).then((data) => {
console.log(data);
});
});
deviceBtn.addEventListener("click", () => {
sendRequest(BASE_URL + deviceUrl).then((data) => {
console.log(data);
});
});
async function sendRequest(url) {
console.log("start");
const result = await fetch(url)
.then((response) => {
if (!response.ok) {
throw new Error("Network response was not ok");
}
return response.json();
})
.catch((error) => {
console.error("There was a problem with your fetch operation:", error);
});
console.log("Result:", result);
return result;
}
async function sendCaptureRequest(url, body) {
try {
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(body),
});
if (!response.ok) {
throw new Error("Network response was not ok");
}
const result = await response.json();
console.log("Result:", result);
return result;
} catch (error) {
console.error("There was a problem with your fetch operation:", error);
}
}