From bee27a8e53a42152d5cf53477adb567b72c68b9f Mon Sep 17 00:00:00 2001 From: Stephen von Takach Date: Wed, 14 Aug 2024 09:57:24 +1000 Subject: [PATCH] fix(signage/playlist_media): don't cleanup media still in use --- src/placeos-rest-api/controllers/signage/playlist_media.cr | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/placeos-rest-api/controllers/signage/playlist_media.cr b/src/placeos-rest-api/controllers/signage/playlist_media.cr index 68d8ef33..138fa14a 100644 --- a/src/placeos-rest-api/controllers/signage/playlist_media.cr +++ b/src/placeos-rest-api/controllers/signage/playlist_media.cr @@ -101,6 +101,12 @@ module PlaceOS::Api {current_item.media, current_item.thumbnail}.each do |upload| next unless upload + # don't remove upload if it's used else where + upload_id = upload.id + counts = Model::Playlist::Item.where("media_id = ? OR thumbnail_id = ? AND id != ?", upload_id, upload_id, current_item.id).count + next unless counts.zero? + + # cleanup files from storage storage = upload.storage || ::PlaceOS::Model::Storage.storage_or_default(authority.id) signer = UploadSigner::AmazonS3.new(storage.access_key, storage.decrypt_secret, storage.region, endpoint: storage.endpoint) signer.delete_file(storage.bucket_name, upload.object_key, upload.resumable_id)