How to use the tinify.AccountError function in tinify

To help you get started, we’ve selected a few tinify examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github skyujilong / tinypng-webpack-plugin / src / uploader.js View on Github external
let compressImg = yield new Promise((resolve, reject) => {
                    tinify.fromBuffer(fileInfo.source.source()).toBuffer((err, resultData) => {
                        if (err) {
                            reject(err);
                        } else {
                            resolve(resultData);
                        }
                    })
                });
                //压缩图片成功
                fileInfo.source._value = compressImg;
                // 缓存压缩后的文件
                let filePath = yield writeImg(compressImg, fileMd5);
                appendDict[fileMd5] = filePath;
            } catch (err) {
                if (err instanceof tinify.AccountError) {
                    // Verify your API key and account limit.
                    if (!keys) {
                        //输出文件名 fileInfo.name
                        uploadErrorList.push(fileInfo.name);
                        return;
                    }
                    //tinify key 更换
                    tinify.key = _.first(keys);
                    keys = _.drop(keys);
                    yield upload(fileInfo, reTryCount);
                } else {
                    // Something else went wrong, unrelated to the Tinify API.
                    yield upload(fileInfo, reTryCount - 1);
                }
            }
        }
github muwoo / tinypng-upload / src / renderer / assets / js / operate.js View on Github external
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)})
github skyujilong / tinypng-webpack-plugin / src / compression.js View on Github external
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
                    });
                }
            });
        })();

tinify

Node.js client for the Tinify API. Tinify compresses your images intelligently. Read more at https://tinify.com.

MIT
Latest version published 2 years ago

Package Health Score

50 / 100
Full package analysis