fix(Delegate): media cleanup issue and log deleteOne
This commit is contained in:
parent
c9a2d79701
commit
09b52a7fc3
2 changed files with 9 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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')
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue