Skip to content

Instantly share code, notes, and snippets.

@birinder-lobana
Last active April 19, 2022 18:04
Show Gist options
  • Save birinder-lobana/5ab173d595e211e58b20ede62973c29f to your computer and use it in GitHub Desktop.
Save birinder-lobana/5ab173d595e211e58b20ede62973c29f to your computer and use it in GitHub Desktop.
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