add checking so only PDFs are saved locally

image files can be too big for local storage to handle.  (better to have reliability)
This commit is contained in:
Billy Lo 2021-11-01 10:43:20 -04:00
parent e8806c7631
commit 082a02f0e7
3 changed files with 6 additions and 4 deletions

View File

@ -161,10 +161,11 @@ function Form(): JSX.Element {
async function storeFileToLocalStorageBase64(key: string, file: File) {
if (window.localStorage) {
if (window.localStorage && file.type.includes('application/pdf')) {
// https://stackoverflow.com/a/56738510/2789065
console.log('storing buffer ' + file.type);
const buffer = Buffer.from(await new Response(file).arrayBuffer());
let dataUrl = `data:${file.type};base64,${buffer.toString("base64")}`;
localStorage.setItem(key, dataUrl);
@ -177,7 +178,7 @@ function Form(): JSX.Element {
const payload = await getPayloadBodyFromFile(file);
payload.dataUrl = "receipt";
console.log(file2);
console.log(file);
if (file2) {
payload.extraUrl = file2.name;

View File

@ -111,7 +111,7 @@ function Index(): JSX.Element {
<br />
<br />
<ul className="list-decimal list-outside" style={{ marginLeft: '20px' }}>
<li><b>New for iPhone users: You can now quickly access the original PDF receipt from your wallet pass</b> (by tapping ... on the top right to see details). If you have already imported your pass, just delete the old one and re-import to get this convenience feature.</li>
<li><b>New for iPhone users: You can now quickly access the original PDF receipt from your wallet pass</b> (by tapping ... on the top right to see details). If you have already created a Wallet pass, you can delete the old one and re-import to get this convenience feature.</li>
<li>Thank you very much to the Government of Nunavut for proactively reaching out to us to allow us to add support for Nunavummiut!</li>
<li>Support for newly-released Manitoba federal-standard QR codes</li>
<li>(Often-requested) support added for importing proof-of-vaccination into <b>Google Pay</b> on Android 8.1+</li>

View File

@ -23,6 +23,7 @@
function clearLocalStorage() {
localStorage.clear();
document.getElementById('image').hidden = true;
document.getElementById('msg').innerHTML = 'Local storage cleared.';
document.getElementById('clearButton').hidden = true;
}
@ -53,7 +54,7 @@
<body>
<img id='image' width="100%" />
<br />
<input id='clearButton' type="button" hidden value='Clear Local Storage' onclick="clearLocalStorage()"></input>
<input id='clearButton' class='big-text' type="button" hidden value='Clear Local Storage' onclick="clearLocalStorage()"></input>
<div id='msg' class='center big-text' width="100%" />
<script>