mirror of
				https://github.com/iv-org/invidious.git
				synced 2025-10-31 20:51:56 +00:00 
			
		
		
		
	Pick a different instance upon redirect
This commit is contained in:
		| @@ -40,14 +40,23 @@ module Invidious::Routes::Misc | ||||
|  | ||||
|   def self.cross_instance_redirect(env) | ||||
|     referer = get_referer(env) | ||||
|     redirect_url = "redirect.invidious.io" | ||||
|  | ||||
|     instance_list = Invidious::Jobs::InstanceListRefreshJob::INSTANCES["INSTANCES"] | ||||
|     if instance_list.empty? | ||||
|       instance_url = "redirect.invidious.io" | ||||
|       instance_url = redirect_url | ||||
|     else | ||||
|       # Sample returns an array | ||||
|       # Instances are packaged as {region, domain} in the instance list | ||||
|       instance_url = instance_list.sample(1)[0][1] | ||||
|       # 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.any? | ||||
|         instance_url = other_available_instances.sample(1)[0][1] | ||||
|       else | ||||
|         # If the current instance is the only one, use the redirect URL as fallback | ||||
|         instance_url = redirect_url | ||||
|     end | ||||
|  | ||||
|     env.redirect "https://#{instance_url}#{referer}" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 epicsam123
					epicsam123