Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
static loadUrl( url, callback ) {
// base64 encode the loaded image
base64.base64encoder( url, {
string: true
}, function( err, image ) {
if ( err ) {
console.log(err);
return;
}
if ( callback ) {
callback( image );
}
} );
}
try {
// Check for a custom asset
fs.statSync( filePath );
} catch( e ) {
try {
// No custom assets exists, look in the core assets directory
filePath = path.join( __dirname, '../setup/core/assets/', fileName );
fs.statSync( filePath );
} catch( e2 ) {
console.warn(`[bot] Asset: ${filePath} not found!`);
return;
}
}
// base64 encode the loaded image
base64.base64encoder( filePath, {
localFile: true,
string: true
}, function( err, image ) {
if ( err ) {
console.log(err);
return;
}
if ( callback ) {
callback( image );
}
} );
}
}
grunt.registerTask("generate-icon", function () {
var iconPath = path.join(currentFolder, "/icon.png"),
options = {localFile: true, string: true},
done = this.async();
grunt.log.writeln("Processing icon");
if (!grunt.file.exists(iconPath) || !grunt.file.exists(WIDGET_XML)) {
grunt.log.error("can\'t generate icon");
return done();
}
base64.base64encoder(iconPath, options, function (err, image) {
if (!err) {
var xmlOld = grunt.file.read(WIDGET_XML);
parser.parseString(xmlOld, function (err, result) {
if (!err) {
if (result && result.widget && result.widget.icon) {
result.widget.icon[0] = image;
}
var xmlString = builder.buildObject(result);
grunt.file.write(WIDGET_XML, xmlString);
done();
}
});
} else {
grunt.log.error("can\'t generate icon");
return done();
}
function getImageAnalysis(opts, done) {
var imageURL;
if (opts) {
imageURL = opts.imageURL;
}
base64.base64encoder(imageURL, encooderOpts, sb(analyzeImage, done));
}