Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getPixels(input.src,function(err,pixels){
if(err) throw err;
var w = pixels.shape[0];
var h = pixels.shape[1];
var decoded = jsQR.decodeQRFromImage(pixels.data,w,h);
// This output is accessible to Image Sequencer
step.output = input;
step.output.data = decoded;
// Tell Image Sequencer that this step is complete
callback();
options.step.qrval = decoded;
});
jimp.read(buffer, (err, image) => {
if (err){ return callback(err); }
// 2. Decode QRCode
let data = jsQr.decodeQRFromImage(image.bitmap.data, image.bitmap.width, image.bitmap.height);
// 3. Check is JSON
try {
let json = JSON.parse(data);
return callback(undefined, json);
} catch (ex) { /* exception */ }
// 4. Is string
if (data.indexOf('http') !== 0) {
return callback(undefined, { 'text' : data });
}
// 5. Parse URL parameters
let qs = data.indexOf('?')
if (qs < 0) return callback(undefined, { url : data });
jimp.read(buffer, (err, image) => {
if(err){
return node.error(err);
}
//Decode
let jsonQrData = jsQr.decodeQRFromImage(image.bitmap.data, image.bitmap.width, image.bitmap.height);
//safe parsing of qrCode message to json object
try {
msg[node.output] = JSON.parse(jsonQrData);
} catch (ex) {
//if it is an URL
if(jsonQrData.match(/^http(s)?:\/\//)){
//Save the full URL
let urlTab, params, paramsTab, url = jsonQrData;
msg[node.output] = {};
msg[node.output].url = url;
urlTab = url.split('?');
if(urlTab.length > 1){
params = urlTab[1];
msg[node.output].params = {};
paramsTab = params.split('&');
//Save every params of the URL in an object
var scan = function (evt) {
if ($window.localMediaStream) {
var size = 250
context.drawImage(video, 0, 0, size, size)
var imageData = context.getImageData(0, 0, size, size)
var decoded = jsqr.decodeQRFromImage(imageData.data, size, size)
if (typeof (decoded) !== 'undefined' && decoded.length > 0) {
cancel()
$scope.onSuccess(parseDecoded(decoded))
}
}
}