From 43a5234ab3851ff7869b717f49dac16097b158ee Mon Sep 17 00:00:00 2001 From: dbroqua Date: Tue, 12 Mar 2019 22:51:32 +0100 Subject: [PATCH] Fixed bug --- libs/aws.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libs/aws.js b/libs/aws.js index 5b365c2..aaf5434 100644 --- a/libs/aws.js +++ b/libs/aws.js @@ -6,14 +6,14 @@ const imageminJpegtran = require('imagemin-jpegtran') const imageminPngquant = require('imagemin-pngquant') class Aws { - constructor() { + constructor () { AWS.config.update({ accessKeyId: process.env.AWS_ACCESS_KEY_ID, secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY }) } - _send(params, callback) { + _send (params, callback) { fs.readFile(params.path, (err, data) => { if (err) { callback(err, null) @@ -40,7 +40,7 @@ class Aws { }) } - _compress(params, callback) { + _compress (params, callback) { const newFile = params.path + '.' + params.filename.split('.')[1] fs.copyFile(params.path, newFile, (err, res) => { @@ -50,7 +50,6 @@ class Aws { } try { - (async () => { const file = await imagemin([newFile], '/tmp', { plugins: [ @@ -69,8 +68,9 @@ class Aws { fs.unlink(file[0].path, () => { }) }) })() + } catch (e) { + callback(e) } - catch (callback) }) } @@ -79,7 +79,7 @@ class Aws { * @param {Object} params {path: String, filename: String} * @param {Function} callback */ - upload(params, callback) { + upload (params, callback) { fs.readFile(params.path, (err, data) => { if (err) { callback(err, null) @@ -90,7 +90,7 @@ class Aws { }) } - deleteObjects(files, callback) { + deleteObjects (files, callback) { const s3 = new AWS.S3() const basePath = process.env.AWS_URL + process.env.AWS_BASEFOLDER let items = []