alpha test
This commit is contained in:
parent
3d89a5b0ee
commit
437bb8be4a
|
@ -1,6 +1,6 @@
|
||||||
API_BASE_URL=http://localhost
|
API_BASE_URL=http://192.168.2.200
|
||||||
VERIFIER_HOST=http://localhost:5001/grassroot-verifier/us-central1
|
VERIFIER_HOST=http://192.168.2.200:5001/grassroot-verifier/us-central1
|
||||||
HITCOUNT_HOST=http://localhost:8080
|
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
|
FUNCTION_SUFFIX=v2
|
||||||
GPAY_BASE_URL=http://localhost:5002/grassroots-gpay/us-central1/googlesign
|
GPAY_BASE_URL=http://localhost:5002/grassroots-gpay/us-central1/googlesign
|
||||||
|
|
|
@ -32,3 +32,4 @@ yarn-error.log*
|
||||||
|
|
||||||
# Idea files
|
# Idea files
|
||||||
.idea
|
.idea
|
||||||
|
*.local
|
||||||
|
|
|
@ -125,6 +125,7 @@ function Form(): JSX.Element {
|
||||||
_setFileErrorMessages([]);
|
_setFileErrorMessages([]);
|
||||||
checkBrowserType();
|
checkBrowserType();
|
||||||
const payloadBody = await getPayload(selectedFile);
|
const payloadBody = await getPayload(selectedFile);
|
||||||
|
await createDataUrlForDisplay(selectedFile);
|
||||||
await renderPhoto(payloadBody);
|
await renderPhoto(payloadBody);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -132,9 +133,68 @@ function Form(): JSX.Element {
|
||||||
checkBrowserType();
|
checkBrowserType();
|
||||||
}, [inputFile])
|
}, [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> {
|
async function getPayload(file) : Promise<PayloadBody> {
|
||||||
try {
|
try {
|
||||||
const payload = await getPayloadBodyFromFile(file);
|
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);
|
setPayloadBody(payload);
|
||||||
setFileLoading(false);
|
setFileLoading(false);
|
||||||
setFile(file);
|
setFile(file);
|
||||||
|
@ -390,7 +450,6 @@ function Form(): JSX.Element {
|
||||||
const newUrl = `https://pay.google.com/gp/v/save/${jwt}`;
|
const newUrl = `https://pay.google.com/gp/v/save/${jwt}`;
|
||||||
console.log('> redirect to save Google Pass');
|
console.log('> redirect to save Google Pass');
|
||||||
|
|
||||||
// saveAs(passBlob, covidPassFilename);
|
|
||||||
setSaveLoading(false);
|
setSaveLoading(false);
|
||||||
window.location.href = newUrl;
|
window.location.href = newUrl;
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -43,7 +43,7 @@
|
||||||
"node-fetch": "^2.6.1",
|
"node-fetch": "^2.6.1",
|
||||||
"node-jose": "^2.0.0",
|
"node-jose": "^2.0.0",
|
||||||
"node-pdf-verifier": "^1.0.1",
|
"node-pdf-verifier": "^1.0.1",
|
||||||
"pdfjs-dist": "^2.6.347",
|
"pdfjs-dist": "^2.10.377",
|
||||||
"pngjs": "^6.0.0",
|
"pngjs": "^6.0.0",
|
||||||
"qrcode": "^1.4.4",
|
"qrcode": "^1.4.4",
|
||||||
"react": "^17.0.2",
|
"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 {Constants} from "./constants";
|
||||||
import {COLORS} from "./colors";
|
import {COLORS} from "./colors";
|
||||||
|
import link from "next/link";
|
||||||
|
|
||||||
export class Receipt {
|
export class Receipt {
|
||||||
constructor(public name: string, public vaccinationDate: string, public vaccineName: string, public dateOfBirth: string, public numDoses: number, public organization: string) {};
|
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 {
|
interface Field {
|
||||||
key: string;
|
key: string;
|
||||||
label: string;
|
label: string;
|
||||||
value: string;
|
value?: string;
|
||||||
textAlignment?: string;
|
textAlignment?: string;
|
||||||
|
attributedValue?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PassDictionary {
|
export interface PassDictionary {
|
||||||
|
@ -41,6 +43,7 @@ export interface PayloadBody {
|
||||||
rawData: string;
|
rawData: string;
|
||||||
receipts: HashTable<Receipt>;
|
receipts: HashTable<Receipt>;
|
||||||
shcReceipt: SHCReceipt;
|
shcReceipt: SHCReceipt;
|
||||||
|
dataUrl?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Payload {
|
export class Payload {
|
||||||
|
@ -48,6 +51,7 @@ export class Payload {
|
||||||
receipts: HashTable<Receipt>;
|
receipts: HashTable<Receipt>;
|
||||||
shcReceipt: SHCReceipt;
|
shcReceipt: SHCReceipt;
|
||||||
rawData: string;
|
rawData: string;
|
||||||
|
dataUrl?: string;
|
||||||
backgroundColor: string;
|
backgroundColor: string;
|
||||||
labelColor: string;
|
labelColor: string;
|
||||||
foregroundColor: string;
|
foregroundColor: string;
|
||||||
|
@ -62,6 +66,7 @@ export class Payload {
|
||||||
this.receipts = body.receipts;
|
this.receipts = body.receipts;
|
||||||
this.shcReceipt = body.shcReceipt;
|
this.shcReceipt = body.shcReceipt;
|
||||||
this.rawData = body.rawData;
|
this.rawData = body.rawData;
|
||||||
|
this.dataUrl = body.dataUrl;
|
||||||
this.generic = {
|
this.generic = {
|
||||||
headerFields: [],
|
headerFields: [],
|
||||||
primaryFields: [],
|
primaryFields: [],
|
||||||
|
@ -77,112 +82,34 @@ export class Payload {
|
||||||
this.foregroundColor = COLORS.BLACK;
|
this.foregroundColor = COLORS.BLACK;
|
||||||
this.img1x = Constants.img1xBlack;
|
this.img1x = Constants.img1xBlack;
|
||||||
this.img2x = Constants.img2xBlack;
|
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
|
const displayLocallyStoredPDFUrl = window.location.href + "/displayLocallyStoredPDF.html";
|
||||||
this.expirationDate = '2021-10-22T23:59:59-04:00';
|
const attributedValue = `<a href="${displayLocallyStoredPDFUrl}">Display locally stored PDF</a>`;
|
||||||
this.generic.auxiliaryFields.push({
|
console.log('*** attributedValue ***');
|
||||||
key: "expiry",
|
console.log(attributedValue);
|
||||||
label: "QR code expiry",
|
|
||||||
value: '2021-10-22'
|
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}`);
|
let script = `function debugBase64(base64URL){
|
||||||
|
var win = window.open();
|
||||||
const name = receipt['name'];
|
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>');
|
||||||
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,
|
|
||||||
}
|
}
|
||||||
);
|
debugBase64('${dataUrl}');
|
||||||
|
`;
|
||||||
|
|
||||||
if (generic.auxiliaryFields.length == 0) {
|
let hrefValue = `javascript:${script};`
|
||||||
generic.auxiliaryFields.push(
|
return hrefValue;
|
||||||
{
|
|
||||||
key: "name",
|
|
||||||
label: "Name",
|
|
||||||
value: name
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: "dob",
|
|
||||||
label: "Date of Birth",
|
|
||||||
value: dateOfBirth
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return fullyVaccinated;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function processSHCReceipt(receipt: SHCReceipt, generic: PassDictionary) {
|
function processSHCReceipt(receipt: SHCReceipt, generic: PassDictionary) {
|
||||||
|
@ -194,7 +121,7 @@ function processSHCReceipt(receipt: SHCReceipt, generic: PassDictionary) {
|
||||||
{
|
{
|
||||||
key: "name",
|
key: "name",
|
||||||
label: "",
|
label: "",
|
||||||
value: `${receipt.name} (${receipt.dateOfBirth})`
|
value: `${receipt.name}`
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue