in website-creator/website-helper.js [76:132]
function uploadToS3(filelist, index, destS3Bucket, destS3KeyPrefix, region, connectInstanceName, cb) {
if (filelist.length > index) {
var response = fs.readFileSync(filelist[index], 'utf8');
var fileDetails = filelist[index]
fileDetails = fileDetails.substring(2, fileDetails.length);
let params2 = {
Bucket: destS3Bucket,
Key: destS3KeyPrefix + '/' + fileDetails,
Body: response
};
if (filelist[index].endsWith('.htm') || filelist[index].endsWith('.html')) {
params2.ContentType = "text/html";
} else if (filelist[index].endsWith('.css')) {
params2.ContentType = "text/css";
} else if (filelist[index].endsWith('.js')) {
params2.ContentType = "application/javascript";
response = response.replace(/CUSTOMER-CONNECT-INSTANCE/g, connectInstanceName).replace(/CUSTOMER-CONNECT-REGION/g, region);
params2.Body = response;
} else if (filelist[index].endsWith('.png')) {
params2.ContentType = "image/png";
} else if (filelist[index].endsWith('.jpg') || filelist[index].endsWith('.jpeg')) {
params2.ContentType = "image/jpeg";
} else if (filelist[index].endsWith('.pdf')) {
params2.ContentType = "application/pdf";
} else if (filelist[index].endsWith('.gif')) {
params2.ContentType = "image/gif";
} else if (filelist[index].endsWith('.svg')) {
params2.ContentType = "image/svg+xml";
};
s3.putObject(params2, function(err, data) {
if (err) {
console.log(err);
return cb(['error copying ', [filelist[index]].join('/'), '\n', err]
.join(
''),
null);
}
console.log([
[filelist[index]].join('/'), 'uploaded successfully'
].join(' '));
let _next = index + 1;
uploadToS3(filelist, _next, destS3Bucket, destS3KeyPrefix, region, connectInstanceName, function(err, resp) {
if (err) {
return cb(err, null);
}
cb(null, resp);
});
});
} else {
cb(null, [index, 'files copied'].join(' '));
}
}