Skip to content

Commit

Permalink
fix: handle orientation for resize, speed up deletes
Browse files Browse the repository at this point in the history
  • Loading branch information
nhoss2 committed Jul 3, 2024
1 parent 05baae9 commit e709cee
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
25 changes: 21 additions & 4 deletions src/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export const processAndUploadImage = async (
(height !== undefined && metadata.height! > height)
) {
processedImage = sharp(imageBuffer)
.rotate()
.resize(width, height)
.toFormat(ext, { quality });
} else {
Expand Down Expand Up @@ -188,11 +189,27 @@ export const deleteUnmatchedImages = async (
bucketName: string,
unmatchedOutputImageKeys: string[]
) => {
const s3Client = await getClient();
const deleteTasks = unmatchedOutputImageKeys.map(
(unmatchedOutputImageKey, index) => {
limiter.schedule(() => {
const deleteWithLog = async () => {
logger.info(
ansis.gray(
`${index + 1}/${
unmatchedOutputImageKeys.length
}: deleting key ${unmatchedOutputImageKey}`
)
);
const s3Client = await getClient();
return deleteImage(bucketName, unmatchedOutputImageKey, s3Client);
};

return deleteWithLog();
});
}
);

for (const unmatchedOutputImageKey of unmatchedOutputImageKeys) {
await deleteImage(bucketName, unmatchedOutputImageKey, s3Client);
}
await Promise.all(deleteTasks);
};

const parseExifData = async (imgData: Buffer): Promise<number | null> => {
Expand Down
2 changes: 1 addition & 1 deletion src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export const getPartialProcessedImages = (
uniqueSourceKeys.size === 1 ? imgs[0].sourceKey : undefined;

if (inputKey === undefined) {
logger.warn("unable to find input key for imgs: ", imgs);
logger.debug("unable to find input key for imgs: %o", imgs);
continue;
}

Expand Down

0 comments on commit e709cee

Please sign in to comment.