Last active
April 19, 2022 18:04
-
-
Save birinder-lobana/5ab173d595e211e58b20ede62973c29f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('dotenv').config() | |
const { Openscreen } = require('@openscreen/sdk') | |
// initialize Openscreen SDK | |
const os = new Openscreen().config({ | |
key: process.env.OS_API_KEY, | |
secret: process.env.OS_API_SECRET, | |
}) | |
// script that generates a QR code in the project's /public directory | |
// using the Openscreen SDK. | |
const generateQrCode = async () => { | |
console.log('Generating a new QR code...') | |
// create asset in Openscreen | |
const asset = await os | |
.project(process.env.OS_PROJECT_ID) | |
.assets() | |
.create({ | |
name: 'my-qrcode-app', | |
qrCodes: [ | |
{ | |
intent: 'https://www.my-qrcode-app.com', | |
intentType: 'DYNAMIC_REDIRECT', | |
}, | |
], | |
}) | |
// create qr code in Openscreen | |
const qrCodeId = asset.asset.qrCodes[0].qrCodeId | |
const qrCode = await os.qrCode(qrCodeId).get({ | |
format: 'PNG', | |
scale: 12, | |
background: '#ffffff', | |
foreground: '#000000', | |
dataUrl: true, | |
}) | |
// generate qr code image in the /public directory | |
await os.saveQrImageDataToFile(qrCode, 'public/qrCode.png') | |
console.log('QR code created!') | |
} | |
// run script | |
generateQrCode() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment