Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (url.indexOf('http://') !== 0 && url.indexOf('https://') !== 0) {
if (fs.readdirSync(path.resolve(projectPath, 'hosted_logos')).indexOf(url) === -1) {
throw new Error(`there is no file ${url} in a hosted_logos folder`);
}
response = fs.readFileSync(path.resolve(projectPath, 'hosted_logos', url));
} else {
response = await rp({
encoding: null,
uri: url,
followRedirect: true,
maxRedirects: 5,
simple: true,
timeout: 30 * 1000
});
}
const croppedSvgResult = await autoCropSvg(response, {title: `${item.name} logo`});
const croppedSvg = croppedSvgResult.result;
require('fs').writeFileSync(path.resolve(projectPath, `cached_logos/${fileName}`), croppedSvg);
reporter.write(cacheMiss('*'));
return {
fileName: fileName,
name: item.name,
logo: item.logo,
hash: hash
};
} catch(ex) {
debug(`Cannot fetch ${url}`);
const message = ex.message || ex || 'Unknown error';
if (cachedEntry && imageExist(cachedEntry)) {
addWarning('image');
reporter.write(error('E'));
errors.push(error(`Using cached entry, because ${item.name} has issues with logo: ${url}, ${message}`));