diff --git a/config/gulp/file-upload.js b/config/gulp/file-upload.js index 41ded5d44b..f50afa6d36 100644 --- a/config/gulp/file-upload.js +++ b/config/gulp/file-upload.js @@ -24,7 +24,9 @@ const headers = { function uploadImage() { return gulp - .src("content/uploads/_working-images/processed/*") + .src("content/uploads/_working-images/processed/*", { + encoding: false, + }) .pipe(publisher.publish(headers)) .pipe( awspublish.reporter({ @@ -44,7 +46,9 @@ function uploadFile() { }); return gulp - .src("content/uploads/_working-files/to-process/*") + .src("content/uploads/_working-files/to-process/*", { + removeBOM: true, + }) .pipe(staticRename) .pipe(publisher.publish(headers)) .pipe( @@ -61,20 +65,18 @@ function uploadFile() { function cleanup() { return new Promise((resolve, reject) => { let imageDir = "content/uploads/_working-images/processed"; - let fileDir = "content/uploads/_working-files/to-process"; + let fileDir = "content/uploads/_working-files"; if (fs.existsSync(imageDir)) { - if (fs.readdirSync(imageDir).length > 0) { - console.log(`Images have number of files ${fs.readdirSync(imageDir).length}`); - // delete tht folder - del([imageDir]); - resolve(); - } else { - resolve(); - } - } else { - resolve(); + // remove the folder + del([imageDir]); + } + + if (fs.existsSync(fileDir)) { + // remove the folder + del([fileDir]); } + resolve(); }); } @@ -114,33 +116,19 @@ function determineWhichToUpload() { if (imageFiles.length > 0) { uploadsToComplete += 1; - const imageUploadStream = uploadImage(); - imageUploadStream.on('finish', () => { - uploadsCompleted += 1; - checkCompletion(); - }); - imageUploadStream.on('error', (err) => { - console.error("Error uploading images:", err); - reject(err); - }); + uploadImage(); + uploadsCompleted += 1; + checkCompletion(); } if (fileFiles.length > 0) { uploadsToComplete += 1; - const fileUploadStream = uploadFile(); - fileUploadStream.on('finish', () => { - uploadsCompleted += 1; - checkCompletion(); - }); - fileUploadStream.on('error', (err) => { - console.error("Error uploading files:", err); - reject(err); - }); + uploadFile(); + uploadsCompleted += 1; + checkCompletion(); } - if (uploadsToComplete === 0) { - resolve(); // If no uploads are initiated, resolve immediately. - } + return resolve(); }); }