Skip to content

Commit

Permalink
fix(signage/playlist_media): don't cleanup media still in use
Browse files Browse the repository at this point in the history
  • Loading branch information
stakach committed Aug 13, 2024
1 parent c89d12b commit bee27a8
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/placeos-rest-api/controllers/signage/playlist_media.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit bee27a8

Please sign in to comment.