diff --git a/src/MediaService.ts b/src/MediaService.ts index d96f59f..88911f5 100644 --- a/src/MediaService.ts +++ b/src/MediaService.ts @@ -25,6 +25,7 @@ export default class MediaService { } static delete(key: string, context: string) { + console.log('> MediaCleanup: in context "' + context + '" deleteOne', key) MediaService.getS3().deleteObject({ Bucket: MediaService.getBucket(), Key: key diff --git a/src/controllers/DelegateController.ts b/src/controllers/DelegateController.ts index 9978db6..6aa464b 100644 --- a/src/controllers/DelegateController.ts +++ b/src/controllers/DelegateController.ts @@ -101,8 +101,15 @@ export default class DelegateController { proposedVersion.gallery = [] } if (Array.isArray(organization.proposedVersion.gallery)) { + // we take all the media from the old proposed version + // we filter and we delete a media only if: + // not seen in the publishedVersion gallery + // not seen in the new proposed gallery let toDeleteMedias = organization.proposedVersion.gallery - .filter((media: any) => proposedVersion.gallery.filter((m: any) => m.key === media.key).length === 0) + .filter((media: any) => + organization.publishedVersion.gallery.filter((m: any) => m.key === media.key).length === 0 && + proposedVersion.gallery.filter((m: any) => m.key === media.key).length === 0 + ) .map((media: any) => media.key) MediaService.deleteMany(toDeleteMedias, 'galleryUpdated') }