122 lines
5.3 KiB
JavaScript
122 lines
5.3 KiB
JavaScript
function docReady(fn) {
|
|
// see if DOM is already available
|
|
if (document.readyState === "complete" || document.readyState === "interactive") {
|
|
// call on next available tick
|
|
setTimeout(fn, 1);
|
|
} else {
|
|
document.addEventListener("DOMContentLoaded", fn);
|
|
}
|
|
}
|
|
certClass = function(rawVal) {
|
|
this.cert = rawVal;
|
|
};
|
|
docReady(function() {
|
|
var resultContainer = document.getElementById('qr-reader-results');
|
|
var lastResult, countResults = 0;
|
|
|
|
var html5QrcodeScanner = new Html5QrcodeScanner(
|
|
"qr-reader", { fps: 20, qrbox: 400 });
|
|
|
|
function onScanSuccess(decodedText, decodedResult) {
|
|
if (decodedText !== lastResult) {
|
|
++countResults;
|
|
lastResult = decodedText;
|
|
|
|
input_text = 'HC1:6BFOXN%TS3DHPVO13J /G-/2YRVA.QKW8SFBXG4CH23IRM*4Z8EHLTKQC:3DCV4*XUA2PSGH.+HIMIBRU SITK292W7*RBT1KCGTHQSEQBKLP64-HQ/HQ3IRE+QJDO-B5ET42HPPEPHCR6W9FDON95U/3-58 KE2+GKHG:3D6JK9+GFKMWKN7JJEHGRHHIUJR.KL.KR+G/IKM*G1JJ*KMO-K3OM.IA.C8KRDL4O54O4IGUJKAHIYIABGEX3E1.BLEE$JDG2OFI9L+93NKF9E3-9TC90JA4E15IAXMFU*GZEG-8A%FGSKE MCTPI8%MDPIW7CR5KBBQFZMD11-97S75JWTE.S$7K0:JSCCV7J$%25I3HC31835AL5:4A93OHBIFT.EJDG3L*8B89T3CT7WJI4WCW9WQ$LNU3OU72CWQIU7JBW.22S+5WIA%5RR-ND6RBTE-*6LYQN440Q82TPS2PH1S4%7+V0Q3S0C70T6J3V3VH3Y4430G*5B0';
|
|
//console.log(input_text);
|
|
const myBody = new certClass(input_text);
|
|
const jsonBody= JSON.stringify(myBody);
|
|
// console.log(jsonBody);
|
|
// request options
|
|
const options = {
|
|
method: 'POST',
|
|
body: jsonBody,
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
}
|
|
}
|
|
var obj='';
|
|
fetch('/scan', options).then(function (res) {
|
|
if (res.ok) {
|
|
return res.json();
|
|
// res => res.json();
|
|
// risposta = res.json();
|
|
// html5QrcodeScanner.clear();
|
|
// console.log(risposta);
|
|
// resultContainer.innerHTML += `<div style="background-color:green;text-align:center;padding:20px"><h1>Scansione corretta</h1> <h3> ${risposta.nam.fn} ${risposta.nam.gn} ${risposta.dob}</h3></div>`;
|
|
} else {
|
|
return Promise.reject(res);
|
|
}
|
|
})
|
|
.then(function (risposta)
|
|
{
|
|
html5QrcodeScanner.clear();
|
|
// console.log(risposta);
|
|
resultContainer.innerHTML += `<div style="background-color:green;text-align:center;padding:20px"><h1>Scansione corretta</h1> <h3> ${risposta.nam.fn} ${risposta.nam.gn} ${risposta.dob}</h3></div>`;
|
|
return risposta;
|
|
}
|
|
)
|
|
.then(function (data) {
|
|
|
|
// Store the post data to a variable
|
|
// post = data;
|
|
// contenuto = data;
|
|
var myObject = new Object();
|
|
myObject.contenuto = data;
|
|
const jsonBodyv2 = JSON.stringify(myObject);
|
|
|
|
const data2 = {
|
|
method: 'POST',
|
|
body: jsonBodyv2,
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
}
|
|
}
|
|
|
|
// log 01
|
|
console.log('log1');
|
|
console.log(data2);
|
|
// log 02
|
|
console.log('log2');
|
|
console.log(jsonBodyv2);
|
|
// .then(res => console.log(data2));
|
|
// Fetch another API
|
|
return fetch('/sendc19', data2);
|
|
// .then(res => console.log(res));
|
|
|
|
|
|
}).then(function (response) {
|
|
if (response.ok) {
|
|
window.setTimeout(function(){location.reload()},5000);
|
|
return response;
|
|
} else {
|
|
return Promise.reject(response);
|
|
}
|
|
// }).then(function (data) {
|
|
// console.log(post, data);
|
|
}).catch(function (error) {
|
|
console.warn(error);
|
|
});
|
|
// fetch('/scan', options)
|
|
// .then(res => res.json())
|
|
// .then(res =>
|
|
// {
|
|
// html5QrcodeScanner.clear();
|
|
// console.log(res);
|
|
// resultContainer.innerHTML += `<div style="background-color:green;text-align:center;padding:20px"><h1>Scansione corretta</h1> <h3> ${res.nam.fn} ${res.nam.gn} ${res.dob}</h3></div>`;
|
|
// return fetch('/sendc19',res);
|
|
// //
|
|
// // this.dccress = res;
|
|
// })
|
|
// .catch(err => console.error(err));
|
|
}
|
|
}
|
|
// Optional callback for error, can be ignored.
|
|
function onScanError(qrCodeError) {
|
|
// This callback would be called in case of qr code scan error or setup error.
|
|
// You can avoid this callback completely, as it can be very verbose in nature.
|
|
}
|
|
|
|
html5QrcodeScanner.render(onScanSuccess, onScanError);
|
|
});
|