Files
MatchLiveTv/backend/app/services/youtube/credential_resolver.rb
eminuxandCursor baa6283a15 Mantiene la copertina YouTube se il telefono cade e avvia ffmpeg sul nodo, non via SSH.
Il relay HLS→RTMPS resta sul worker/agent del nodo assegnato, così tre dirette contemporanee restano in onda sul sito e sul canale della società senza schermo nero.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-16 20:41:46 +02:00

63 lines
1.4 KiB
Ruby

module Youtube
class CredentialResolver
VALID_CHANNELS = %w[platform team].freeze
def self.for_team(team, channel: nil)
new(team, channel: channel).resolve
end
def initialize(team, channel: nil)
@team = team
@channel = channel.to_s.presence
@channel = nil unless VALID_CHANNELS.include?(@channel)
@ent = team.entitlements
@mode = @ent.plan.youtube_mode
end
def resolve
case effective_channel
when :platform
PlatformCredential.configured? ? PlatformCredential.new : nil
when :team
@team.club.youtube_credential
end
end
def uses_platform_channel?
effective_channel == :platform
end
def platform_available?
@ent.youtube_enabled? && PlatformCredential.configured?
end
def team_channel_available?
@ent.youtube_enabled? && @ent.premium_full? && @mode == "team" &&
@team.club.youtube_credential&.usable?
end
def effective_channel
if @channel == "platform"
return :platform if platform_available?
elsif @channel == "team"
return :team if team_channel_available?
end
auto_channel
end
private
def auto_channel
if @mode == "matchlivetv_light"
return :platform if platform_available?
elsif @mode == "team"
return :team if team_channel_available?
return :platform if platform_available?
end
nil
end
end
end