let Minio = require('minio');
let sharp = require('sharp');
let uuidV4 = require('uuid/v4');
let config = require('config');
// let decode = require('urldecode');
const _lg = console.log
const _err = console.error
let mcConfig = config.get('config');
let mc = new Minio.Client(mcConfig);
let array = [];
getList = async () => {
let stream = mc.listObjectsV2( 'bucket',
'',
true,
''
);
await stream.on('data', async (obj) => {
await array.push(obj.name);
// console.log(`\'${obj.name}\',`);
});
}
getObject = async () => {
for await (let i of array) {
try {
let oname = i;
let format = oname.substr(oname.indexOf('.')).replace(/./, '');
let optimizedName = oname.replace(/\.[^/.]+$/, "") + (format === "jpg" ? "-optimized.jpg" : "-optimized.png");
imageType = (format === "jpg" ? "image/jpg" : "image/png");
if((/\.(?:jpg|jpeg|png|gif)$/i).test(oname)) {
try {
let dataStreamForOptimized = await mc.getObject(bname, oname);
await (new Promise(function (resolve, reject) {
mc.putObject( mcConfig.destBucket,
optimizedName,
dataStreamForOptimized.pipe(
sharp()
.on('error', e => reject(e))
.rotate()
.on('error', e => reject(e))
.resize(null, 768)
.withMetadata()
.on('error', e => reject(e))
),
imageType,
function(error, etag) {
if (error) {
reject(error)
} else {
resolve(etag)
}
}
);
}));
_lg(`Successfully uploaded: ${optimizedName}`);
} catch(error) {
_lg('Failed to convert image:', oname, error.message);
}
}
} catch (err) {
_err('Failed to handle notification:', err);
}
}
}
const execute = async () => {
await getList();
await getObject();
}
execute();
в функции getObject array пустой приходит. как сделать чтобы передалось значение array?