@@ -498,15 +498,30 @@ def delete_recordings
498498 query_params = { record_id : params [ :recordID ] . split ( ',' ) }
499499 query_params [ :metadata ] = { key : 'tenant-id' , value : @tenant . id } if @tenant . present? # filter based on tenant
500500
501- query = Recording . includes ( :metadata ) . where ( query_params ) . load
501+ query = Recording . includes ( :metadata , :playback_formats ) . where ( query_params ) . load
502502 raise BBBError . new ( 'notFound' , 'We could not find recordings' ) if query . none?
503503
504+ s3_client = Aws ::S3 ::Client . new if ENV [ 'S3_RECORDING' ]
505+
504506 query . each do |rec |
505507 # Start transaction + lock record
506508 rec . with_lock do
507509 logger . debug ( "Deleting recording: #{ rec . record_id } " )
508- # TODO: check the unpublished dir when it is implemented
509- FileUtils . rm_r ( Dir . glob ( File . join ( Rails . configuration . x . recording_publish_dir , '/*/' , rec . record_id ) ) )
510+ if ENV [ 'S3_RECORDING' ]
511+ bucket = ENV . fetch ( 'S3_BUCKET_NAME' )
512+ state = rec . published ? 'published' : 'unpublished'
513+
514+ rec . playback_formats . each do |playback_format |
515+ prefix = "#{ state } /#{ playback_format . format } /#{ rec . record_id } /"
516+ objects = s3_client . list_objects_v2 ( bucket : bucket , prefix : prefix ) . contents
517+ next if objects . empty?
518+
519+ s3_client . delete_objects ( bucket : bucket , delete : { objects : objects . map { |o | { key : o . key } } } )
520+ end
521+ else
522+ # TODO: check the unpublished dir when it is implemented
523+ FileUtils . rm_r ( Dir . glob ( File . join ( Rails . configuration . x . recording_publish_dir , '/*/' , rec . record_id ) ) )
524+ end
510525 rec . mark_delete!
511526 rescue StandardError => e
512527 logger . warn ( "Error #{ e } deleting recording #{ rec . record_id } " )
0 commit comments