From 676b828419ef74173541549ff8574cf2ed45633e Mon Sep 17 00:00:00 2001 From: jer3k <99355997+jer3k@users.noreply.github.com> Date: Wed, 6 Nov 2024 14:43:32 -0800 Subject: [PATCH] fix s3 reporting deleted objects --- backend/src/external/services/s3-api.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/src/external/services/s3-api.ts b/backend/src/external/services/s3-api.ts index 33b12220c..18a09bcbb 100644 --- a/backend/src/external/services/s3-api.ts +++ b/backend/src/external/services/s3-api.ts @@ -124,7 +124,7 @@ export const deleteFiles = async (ids: string[]): Promise> => { try { // Get all the files stored under each id const filesPerId = await Promise.all( - ids.map((id) => getFileList(s3Client, id)), //TODO: try deleting the folders instead of each individual file. https://stackoverflow.com/a/73367823 + ids.map((id) => getFileList(s3Client, id)), ); const idsWithNoFiles = ids.filter( (id, index) => filesPerId[index].length === 0, @@ -150,7 +150,7 @@ export const deleteFiles = async (ids: string[]): Promise> => { // report any errors responsePerGroup.forEach((r) => - r.Errors.forEach((e) => { + r.Errors?.forEach((e) => { if (e.Code == 'NoSuchKey') idsWithNoFiles.push(getIdFromKey(e.Key)); logger.error(e.Message); }), @@ -158,7 +158,7 @@ export const deleteFiles = async (ids: string[]): Promise> => { // Return the id of all successful deleted const successfulIds = responsePerGroup.flatMap((r) => - r.Deleted.reduce((acc, x) => { + r.Deleted?.reduce((acc, x) => { acc.push(getIdFromKey(x.Key)); return acc; }, [] as string[]),