alpha test
This commit is contained in:
parent
3d89a5b0ee
commit
437bb8be4a
|
@ -1,6 +1,6 @@
|
|||
API_BASE_URL=http://localhost
|
||||
VERIFIER_HOST=http://localhost:5001/grassroot-verifier/us-central1
|
||||
API_BASE_URL=http://192.168.2.200
|
||||
VERIFIER_HOST=http://192.168.2.200:5001/grassroot-verifier/us-central1
|
||||
HITCOUNT_HOST=http://localhost:8080
|
||||
REGISTRATION_HOST=http://localhost:5001/grassroot-verifier/us-central1
|
||||
REGISTRATION_HOST=http://192.168.2.200:5001/grassroot-verifier/us-central1
|
||||
FUNCTION_SUFFIX=v2
|
||||
GPAY_BASE_URL=http://localhost:5002/grassroots-gpay/us-central1/googlesign
|
||||
|
|
|
@ -32,3 +32,4 @@ yarn-error.log*
|
|||
|
||||
# Idea files
|
||||
.idea
|
||||
*.local
|
||||
|
|
|
@ -125,6 +125,7 @@ function Form(): JSX.Element {
|
|||
_setFileErrorMessages([]);
|
||||
checkBrowserType();
|
||||
const payloadBody = await getPayload(selectedFile);
|
||||
await createDataUrlForDisplay(selectedFile);
|
||||
await renderPhoto(payloadBody);
|
||||
}
|
||||
});
|
||||
|
@ -132,9 +133,68 @@ function Form(): JSX.Element {
|
|||
checkBrowserType();
|
||||
}, [inputFile])
|
||||
|
||||
async function createDataUrlForDisplay(file: File) {
|
||||
|
||||
if (window.localStorage) {
|
||||
|
||||
// https://stackoverflow.com/a/56738510/2789065
|
||||
|
||||
const buffer = Buffer.from(await new Response(file).arrayBuffer());
|
||||
let dataUrl = `data:${file.type};base64,${buffer.toString("base64")}`;
|
||||
localStorage.setItem('pdfDataUrl', dataUrl);
|
||||
// dataUrl = 'https://apple.com';
|
||||
|
||||
|
||||
|
||||
// let script = `function debugBase64(base64URL){
|
||||
// var win = window.open();
|
||||
// win.document.write('<iframe src="' + base64URL + '" frameborder="0" style="border:0; top:0px; left:0px; bottom:0px; right:0px; width:100%; height:100%;" allowfullscreen></iframe>');
|
||||
// }
|
||||
// debugBase64('${dataUrl}');
|
||||
// `;
|
||||
|
||||
// let hrefValue = `javascript:${script};`
|
||||
|
||||
// let aElement = document.createElement('a')
|
||||
// let textNode = document.createTextNode('Click me');
|
||||
// aElement.appendChild(textNode);
|
||||
// aElement.title = 'Click me';
|
||||
// aElement.setAttribute('id', 'mylink');
|
||||
// aElement.setAttribute('href', hrefValue)
|
||||
// // aElement.setAttribute('download', file.name)
|
||||
// // aElement.setAttribute('target', '_blank')
|
||||
|
||||
// document.getElementById('wrapper').appendChild(aElement);
|
||||
|
||||
// console.log('*** outerHTML ***');
|
||||
// console.log(document.getElementById('wrapper').outerHTML)
|
||||
}
|
||||
}
|
||||
|
||||
async function showPDF() {
|
||||
let dataUrl = localStorage.getItem('pdfDataUrl');
|
||||
// console.log(dataUrl)
|
||||
let script = `function debugBase64(base64URL){
|
||||
var win = window.open();
|
||||
win.document.write('<iframe src="' + base64URL + '" frameborder="0" style="border:0; top:0px; left:0px; bottom:0px; right:0px; width:100%; height:100%;" allowfullscreen></iframe>');
|
||||
}
|
||||
debugBase64('${dataUrl}');
|
||||
`;
|
||||
|
||||
let hrefValue = `javascript:${script};`
|
||||
document.getElementById('mylink').setAttribute('href', hrefValue);
|
||||
|
||||
}
|
||||
|
||||
async function getPayload(file) : Promise<PayloadBody> {
|
||||
try {
|
||||
const payload = await getPayloadBodyFromFile(file);
|
||||
|
||||
const buffer = Buffer.from(await new Response(file).arrayBuffer());
|
||||
let dataUrl = `data:${file.type};base64,${buffer.toString("base64")}`;
|
||||
|
||||
payload.dataUrl = dataUrl;
|
||||
|
||||
setPayloadBody(payload);
|
||||
setFileLoading(false);
|
||||
setFile(file);
|
||||
|
@ -390,7 +450,6 @@ function Form(): JSX.Element {
|
|||
const newUrl = `https://pay.google.com/gp/v/save/${jwt}`;
|
||||
console.log('> redirect to save Google Pass');
|
||||
|
||||
// saveAs(passBlob, covidPassFilename);
|
||||
setSaveLoading(false);
|
||||
window.location.href = newUrl;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -43,7 +43,7 @@
|
|||
"node-fetch": "^2.6.1",
|
||||
"node-jose": "^2.0.0",
|
||||
"node-pdf-verifier": "^1.0.1",
|
||||
"pdfjs-dist": "^2.6.347",
|
||||
"pdfjs-dist": "^2.10.377",
|
||||
"pngjs": "^6.0.0",
|
||||
"qrcode": "^1.4.4",
|
||||
"react": "^17.0.2",
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
<html>
|
||||
|
||||
<head>
|
||||
<style>
|
||||
.center {
|
||||
margin: 0;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
-ms-transform: translate(-50%, -50%);
|
||||
transform: translate(-50%, -50%);
|
||||
}
|
||||
|
||||
.big-text {
|
||||
font-size: 40;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<a class='center big-text' id="mylink">Open locally stored PDF</a>
|
||||
|
||||
<script>
|
||||
console.log('start');
|
||||
|
||||
let dataUrl = localStorage.getItem('pdfDataUrl');
|
||||
|
||||
let script = `function showData(base64URL){
|
||||
var win = window.open();
|
||||
win.document.write('<iframe src="' + base64URL + '" frameborder="0" style="border:0; top:0px; left:0px; bottom:0px; right:0px; width:100%; height:100%;" allowfullscreen></iframe>');
|
||||
}
|
||||
showData('${dataUrl}');
|
||||
`;
|
||||
|
||||
let hrefValue = `javascript:${script};`
|
||||
const myLinkElement = document.getElementById('mylink');
|
||||
|
||||
if (dataUrl) {
|
||||
console.log('ready');
|
||||
myLinkElement.setAttribute('href', hrefValue);
|
||||
// myLinkElement.click();
|
||||
} else {
|
||||
myLinkElement.textContent = 'PDF receipt not saved locally.';
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
127
src/payload.ts
127
src/payload.ts
|
@ -1,5 +1,6 @@
|
|||
import {Constants} from "./constants";
|
||||
import {COLORS} from "./colors";
|
||||
import link from "next/link";
|
||||
|
||||
export class Receipt {
|
||||
constructor(public name: string, public vaccinationDate: string, public vaccineName: string, public dateOfBirth: string, public numDoses: number, public organization: string) {};
|
||||
|
@ -25,8 +26,9 @@ export class SHCVaccinationRecord {
|
|||
interface Field {
|
||||
key: string;
|
||||
label: string;
|
||||
value: string;
|
||||
value?: string;
|
||||
textAlignment?: string;
|
||||
attributedValue?: string;
|
||||
}
|
||||
|
||||
export interface PassDictionary {
|
||||
|
@ -41,6 +43,7 @@ export interface PayloadBody {
|
|||
rawData: string;
|
||||
receipts: HashTable<Receipt>;
|
||||
shcReceipt: SHCReceipt;
|
||||
dataUrl?: string;
|
||||
}
|
||||
|
||||
export class Payload {
|
||||
|
@ -48,6 +51,7 @@ export class Payload {
|
|||
receipts: HashTable<Receipt>;
|
||||
shcReceipt: SHCReceipt;
|
||||
rawData: string;
|
||||
dataUrl?: string;
|
||||
backgroundColor: string;
|
||||
labelColor: string;
|
||||
foregroundColor: string;
|
||||
|
@ -62,6 +66,7 @@ export class Payload {
|
|||
this.receipts = body.receipts;
|
||||
this.shcReceipt = body.shcReceipt;
|
||||
this.rawData = body.rawData;
|
||||
this.dataUrl = body.dataUrl;
|
||||
this.generic = {
|
||||
headerFields: [],
|
||||
primaryFields: [],
|
||||
|
@ -77,112 +82,34 @@ export class Payload {
|
|||
this.foregroundColor = COLORS.BLACK;
|
||||
this.img1x = Constants.img1xBlack;
|
||||
this.img2x = Constants.img2xBlack;
|
||||
} else {
|
||||
const fullyVaccinated = processReceipt(body.receipts[numDose], this.generic);
|
||||
if (fullyVaccinated) {
|
||||
this.backgroundColor = COLORS.GREEN;
|
||||
} else {
|
||||
this.backgroundColor = COLORS.YELLOW;
|
||||
}
|
||||
this.labelColor = COLORS.WHITE;
|
||||
this.foregroundColor = COLORS.WHITE;
|
||||
this.img1x = Constants.img1xWhite;
|
||||
this.img2x = Constants.img2xWhite;
|
||||
|
||||
// These are the non-SHC ON receipts, which expire Oct 22nd
|
||||
this.expirationDate = '2021-10-22T23:59:59-04:00';
|
||||
this.generic.auxiliaryFields.push({
|
||||
key: "expiry",
|
||||
label: "QR code expiry",
|
||||
value: '2021-10-22'
|
||||
})
|
||||
const displayLocallyStoredPDFUrl = window.location.href + "/displayLocallyStoredPDF.html";
|
||||
const attributedValue = `<a href="${displayLocallyStoredPDFUrl}">Display locally stored PDF</a>`;
|
||||
console.log('*** attributedValue ***');
|
||||
console.log(attributedValue);
|
||||
|
||||
this.generic.backFields.push({
|
||||
key: "original",
|
||||
label: "Label",
|
||||
attributedValue: attributedValue
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function processReceipt(receipt: Receipt, generic: PassDictionary) : boolean {
|
||||
function createHref(dataUrl) {
|
||||
// https://stackoverflow.com/a/56738510/2789065
|
||||
|
||||
console.log(`processing receipt #${receipt.numDoses}`);
|
||||
|
||||
const name = receipt['name'];
|
||||
const dateOfBirth = receipt.dateOfBirth;
|
||||
const numDoses = receipt.numDoses;
|
||||
const vaccineName = receipt.vaccineName.toLocaleUpperCase();
|
||||
let vaccineNameProper = vaccineName.charAt(0) + vaccineName.substr(1).toLowerCase();
|
||||
|
||||
if (vaccineName.includes('PFIZER'))
|
||||
vaccineNameProper = 'Pfizer (Comirnaty)'
|
||||
|
||||
if (vaccineName.includes('MODERNA'))
|
||||
vaccineNameProper = 'Moderna (SpikeVax)'
|
||||
|
||||
if (vaccineName.includes('ASTRAZENECA') || vaccineName.includes('COVISHIELD'))
|
||||
vaccineNameProper = 'AstraZeneca (Vaxzevria)'
|
||||
|
||||
let doseVaccine = "#" + String(receipt.numDoses) + ": " + vaccineNameProper;
|
||||
let fullyVaccinated = false;
|
||||
|
||||
if (receipt.numDoses > 1 ||
|
||||
vaccineName.toLowerCase().includes('janssen') ||
|
||||
vaccineName.toLowerCase().includes('johnson') ||
|
||||
vaccineName.toLowerCase().includes('j&j')) {
|
||||
fullyVaccinated = true;
|
||||
}
|
||||
|
||||
if (generic.primaryFields.length == 0) {
|
||||
generic.primaryFields.push(
|
||||
{
|
||||
key: "vaccine",
|
||||
label: "Vaccine",
|
||||
value: doseVaccine
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
let fieldToPush = generic.secondaryFields;
|
||||
if (fieldToPush.length > 0) {
|
||||
fieldToPush = generic.backFields;
|
||||
generic.headerFields.push({
|
||||
key: "extra",
|
||||
label: "More",
|
||||
value: "(i)",
|
||||
"textAlignment" : "PKTextAlignmentCenter"
|
||||
});
|
||||
generic.backFields.push({
|
||||
key: "vaccine" + numDoses,
|
||||
label: `Vaccine (Dose ${numDoses})`,
|
||||
value: receipt.vaccineName
|
||||
})
|
||||
}
|
||||
|
||||
fieldToPush.push(
|
||||
{
|
||||
key: "issuer",
|
||||
label: "Authorized Organization",
|
||||
value: receipt.organization
|
||||
},
|
||||
{
|
||||
key: "dov",
|
||||
label: "Vacc. Date",
|
||||
value: receipt.vaccinationDate,
|
||||
let script = `function debugBase64(base64URL){
|
||||
var win = window.open();
|
||||
win.document.write('<iframe src="' + base64URL + '" frameborder="0" style="border:0; top:0px; left:0px; bottom:0px; right:0px; width:100%; height:100%;" allowfullscreen></iframe>');
|
||||
}
|
||||
);
|
||||
debugBase64('${dataUrl}');
|
||||
`;
|
||||
|
||||
if (generic.auxiliaryFields.length == 0) {
|
||||
generic.auxiliaryFields.push(
|
||||
{
|
||||
key: "name",
|
||||
label: "Name",
|
||||
value: name
|
||||
},
|
||||
{
|
||||
key: "dob",
|
||||
label: "Date of Birth",
|
||||
value: dateOfBirth
|
||||
});
|
||||
}
|
||||
|
||||
return fullyVaccinated;
|
||||
let hrefValue = `javascript:${script};`
|
||||
return hrefValue;
|
||||
}
|
||||
|
||||
function processSHCReceipt(receipt: SHCReceipt, generic: PassDictionary) {
|
||||
|
@ -194,7 +121,7 @@ function processSHCReceipt(receipt: SHCReceipt, generic: PassDictionary) {
|
|||
{
|
||||
key: "name",
|
||||
label: "",
|
||||
value: `${receipt.name} (${receipt.dateOfBirth})`
|
||||
value: `${receipt.name}`
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue