Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
#!/usr/bin/env node
const qr = require('qrcode')
const argv = require('minimist')(process.argv.slice(2), { string: '_' })
const generatePayload = require('./')
const target = String(argv._[0]).replace(/-/g, '')
if (!/^(0|66)\d{9}|\d{13}$/.test(target)) {
console.error('Invalid recipient given: expected tax id or phone number')
process.exit(1)
}
const payload = generatePayload(target, { amount: +argv.amount || +argv._[1] })
console.log(payload)
qr.toString(payload, { type: 'terminal', errorCorrectionLevel: 'L' }, (e, s) => {
if (e) throw e
console.log(s)
})
update (payload) {
this.payload = payload
qr.toString(payload, { type: 'svg', errorCorrectionLevel: 'L' }, (err, svg) => {
if (err) {
window.alert('Cannot generate QR code: ' + String(err))
return
}
if (this.payload === payload) {
const sizeMatch = /width="(\d+)" height="(\d+)"/.exec(svg)
if (!sizeMatch) {
window.alert('Failed to parse SVG...')
return
}
const width = sizeMatch[1] / 4
const height = sizeMatch[2] / 4
const regexp = /x="(\d+)" y="(\d+)"/g
const pixels = [ ]
for (;;) {
const m = regexp.exec(svg)
genQrCode = (data) => {
qrcode.toString(data, (err, qr) => {
if (err) throw err;
this.parseSVG(qr);
});
};
new Promise((yay, nay) => {
qrcode.toString(
`otpauth://totp/${field}?secret=${x}&issuer=${issuer || 'Olymp'}`,
{ type: 'svg' },
(err, data) => (err ? nay(err) : yay(data)),
);
});
const cleanUser = ({ salt, hash, confirmed, _id, ...rest }) => rest;
const qr = (email, x, issuer) => new Promise((yay, nay) => {
require('qrcode').toString(`otpauth://totp/${email}?secret=${x}&issuer=${issuer || 'Olymp'}`, { type: 'svg' }, (err, data) => err ? nay(err) : yay(data));
});
const cleanUser = (user) => {
genQrCode = () => {
const { rtcId } = this.props;
if (rtcId) {
qrcode.toString(rtcId, (err, data) => {
if (err) throw err;
this.setState({
qrcode: data,
});
});
}
};
await withSpinnerAsync(`Creating QR code with '${TEXT}' ...`, async (spinner) => {
await fs.writeFile(
outputFile,
await qrcode.toString(TEXT, QRCODE_OPTIONS),
'utf8'
);
spinner.text = `Saved QR code with '${TEXT}' to '${outputFile}'`;
});
}
function displayFiles(req, res, data, statusCode = 200) {
res.status(statusCode);
if(isPretty(req) && !hasFlag(req, 'drop-upload')) {
res.render('links', data.files ? data : { files: [data] });
} else if(isShort(req)) {
const files = data.files ? data.files : [data];
if(data.archive) files.push(data.archive);
res.send(files.map(file => file.status === 'success' ? file.link.short : file.message).join('\n'));
} else if(hasFlag(req, 'qr')) {
const file = data.archive ? data.archive : (data.files ? data.files[0] : data);
if(file.status === 'success') {
QRCode.toString(file.link.short, { type: hasFlag(req, 'utf8') ? 'utf' : 'terminal' })
.then((qrCode) => { res.send(qrCode); })
.catch(error => res.send('Error while generating QR code.'));
} else {
res.send(file.message);
}
} else {
res.json(data);
}
}