lint edits, refactor

This commit is contained in:
epicsam123 2025-01-25 03:24:38 -05:00 committed by GitHub
parent afb0aad7d3
commit 0fd480bae2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -40,24 +40,19 @@ module Invidious::Routes::Misc
def self.cross_instance_redirect(env) def self.cross_instance_redirect(env)
referer = get_referer(env) referer = get_referer(env)
redirect_url = "redirect.invidious.io"
instance_list = Invidious::Jobs::InstanceListRefreshJob::INSTANCES["INSTANCES"] instance_list = Invidious::Jobs::InstanceListRefreshJob::INSTANCES["INSTANCES"]
if instance_list.empty? # Filter out the current instance
instance_url = redirect_url other_available_instances = instance_list.reject! { |_, domain| domain == CONFIG.domain }
else
# Filter out the current instance
other_available_instances = instance_list.reject! { |region, domain| domain == CONFIG.domain }
# If there are any other instances, select a random one if other_available_instances.empty?
if other_available_instances.any? # If the current instance is the only one, use the redirect URL as fallback
# Sample returns an array instance_url = "redirect.invidious.io"
# Instances are packaged as {region, domain} in the instance list else
instance_url = other_available_instances.sample(1)[0][1] # Select other random instance
else # Sample returns an array
# If the current instance is the only one, use the redirect URL as fallback # Instances are packaged as {region, domain} in the instance list
instance_url = redirect_url instance_url = other_available_instances.sample(1)[0][1]
end
end end
env.redirect "https://#{instance_url}#{referer}" env.redirect "https://#{instance_url}#{referer}"