Skip to content

Commit

Permalink
Allow canister to take QR code from URL parameter (#4)
Browse files Browse the repository at this point in the history
* decode input message in candid

* fix

* fix candid header in epic

* take a query message

Co-authored-by: Yan Chen <[email protected]>
  • Loading branch information
chenyan2002 and chenyan-dfinity authored Sep 14, 2021
1 parent 26bf9ca commit 1598c2d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const data = {

// convert base64 string into ArrayBuffer
async function decode_base64(data) {
const encoded = "data:image/png;base64," + data;
const encoded = "data:application/octet-binary;base64," + data;
const fetched = await fetch(encoded);
const blob = await fetched.blob();
const buffer = await blob.arrayBuffer();
Expand Down Expand Up @@ -279,6 +279,15 @@ function resume_scan() {
}

async function main() {
const params = new URLSearchParams(window.location.search);
const msg = params.get("msg");
if (msg) {
const gzipped = await decode_base64(msg.replace(/_/g, '/').replace(/-/g, '+'));
const unzipped = pako.inflate(gzipped, { to: "string" });
const message = JSON.parse(unzipped);
await prepare_send(message);
return;
}
try {
await init();
while (true) {
Expand All @@ -291,6 +300,7 @@ async function main() {
const scan_button = document.getElementById("scan");
scan_button.innerText = "(video disabled)";
scan_button.disabled = true;
throw err;
}
}

Expand Down

0 comments on commit 1598c2d

Please sign in to comment.