Files
MatchLiveTv/backend/app/services/recordings/delete.rb
T
eminuxandCursor 1d97271555 Aggiunge i18n IT/EN/FR/DE/ES, pagine pubbliche squadre e UX archivio.
Il selettore lingua funziona sul web e sulle app native; su Android la preferenza è persistita e applicata al riavvio. Incluse anche eliminazione replay a scope e campi pagina pubblica squadra.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-23 19:30:44 +02:00

89 lines
2.3 KiB
Ruby

module Recordings
class Delete
SCOPES = %w[both site youtube].freeze
def initialize(recording, reason: :manual, scope: :both)
@recording = recording
@reason = reason
@scope = normalize_scope(scope)
end
def call
case @scope
when "youtube"
delete_youtube_only!
when "site"
delete_site_only!
else
delete_both!
end
@recording
end
private
def normalize_scope(scope)
value = scope.to_s.presence || "both"
SCOPES.include?(value) ? value : "both"
end
def delete_both!
delete_youtube_video
delete_storage_object if @recording.storage_key.present?
cleanup_local_artifacts
@recording.update!(
status: "expired",
deleted_at: Time.current,
storage_key: nil,
thumbnail_storage_key: nil,
youtube_video_id: nil,
youtube_published_at: nil
)
end
def delete_site_only!
delete_storage_object if @recording.storage_key.present?
cleanup_local_artifacts
@recording.update!(
status: "expired",
deleted_at: Time.current,
storage_key: nil,
thumbnail_storage_key: nil
)
end
def delete_youtube_only!
delete_youtube_video
@recording.update!(
youtube_video_id: nil,
youtube_published_at: nil
)
end
def delete_youtube_video
return if @recording.youtube_video_id.blank?
Youtube::VideoLifecycleService.new(@recording).delete!
rescue Youtube::VideoLifecycleService::Error => e
Rails.logger.warn("[Recordings::Delete] YouTube delete #{@recording.id}: #{e.message}")
end
def delete_storage_object
storage = Recordings::Storage.new
storage.delete(key: @recording.storage_key) if @recording.storage_key.present?
storage.delete(key: @recording.thumbnail_storage_key) if @recording.thumbnail_storage_key.present?
rescue Recordings::Storage::Error => e
Rails.logger.warn("[Recordings::Delete] storage delete failed: #{e.message}")
end
def cleanup_local_artifacts
return if @recording.storage_path.blank?
base = File.join(MatchLiveTv.recordings_local_path, @recording.storage_path)
FileUtils.rm_rf(base) if Dir.exist?(base)
end
end
end