Skip to content

Commit

Permalink
rework promise
Browse files Browse the repository at this point in the history
  • Loading branch information
gmrabian committed Nov 14, 2023
1 parent 7e79fe3 commit 045e74e
Showing 1 changed file with 30 additions and 26 deletions.
56 changes: 30 additions & 26 deletions services/uploads/src/clamav.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,37 +77,41 @@ async function downloadAVDefinitions() {
.map((fullPath) => path.basename(fullPath));

// download each file in the bucket.
const downloadPromises = definitionFileKeys.map((filenameToDownload) => {
return async () => {
let destinationFile = path.join("/tmp/", filenameToDownload);
const downloadPromises = await definitionFileKeys.map(
(filenameToDownload) => {
return async () => {
let destinationFile = path.join("/tmp/", filenameToDownload);

utils.generateSystemMessage(
`Downloading ${filenameToDownload} from S3 to ${destinationFile}`
);
utils.generateSystemMessage(
`Downloading ${filenameToDownload} from S3 to ${destinationFile}`
);

let localFileWriteStream = fs.createWriteStream(destinationFile);
let localFileWriteStream = fs.createWriteStream(destinationFile);

let options = {
Bucket: constants.CLAMAV_BUCKET_NAME,
Key: `${constants.PATH_TO_AV_DEFINITIONS}/${filenameToDownload}`,
};
const getObject = new GetObjectCommand(options);
let options = {
Bucket: constants.CLAMAV_BUCKET_NAME,
Key: `${constants.PATH_TO_AV_DEFINITIONS}/${filenameToDownload}`,
};
const getObject = new GetObjectCommand(options);

try {
const response = await S3.send(getObject);
await response.Body.transformToWebStream().pipe(localFileWriteStream);
utils.generateSystemMessage(`Finished download ${filenameToDownload}`);
} catch (err) {
utils.generateSystemMessage(
`Error downloading definition file ${filenameToDownload}`
);
console.log(err);
throw err;
}
};
});
try {
const response = await S3.send(getObject);
await response.Body.transformToWebStream().pipe(localFileWriteStream);
utils.generateSystemMessage(
`Finished download ${filenameToDownload}`
);
} catch (err) {
utils.generateSystemMessage(
`Error downloading definition file ${filenameToDownload}`
);
console.log(err);
throw err;
}
};
}
);

return await downloadPromises();
return downloadPromises;
}

/**
Expand Down

0 comments on commit 045e74e

Please sign in to comment.