Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
tinify.fromBuffer(sourceData).toBuffer((err, resultData) => {
if (err instanceof tinify.AccountError) {
reject(err)
return new Notification('compress filed', {
body: 'Verify your API key and account limit.'
})
} else if (err instanceof tinify.ServerError) {
reject(err)
return new Notification('compress filed', {
body: 'Temporary issue with the Tinify API.'
})
} else if (err instanceof tinify.ConnectionError) {
reject(err)
return new Notification('compress filed', {
body: 'A network connection error occurred.'
})
} else {
resolve({compressFile: resultData, distSize: parseInt(resultData.length / 1024)})
}
})
})
tinify.fromBuffer(fileInfo.data).toBuffer(function(err, resultData) {
if (err instanceof tinify.AccountError && __keys.length > 1) {
//更换秘钥
__keys.splice(0, 1);
tinifyCompress();
} else if (err instanceof tinify.ServerError && __serverErrorRetry -- > 0) {
tinifyCompress();
} else if(err){
reject(err);
} else {
resolve({
dir: fileInfo.dir,
compressionData: resultData
});
}
});
})();