Skip to content

Commit c5e9447

Browse files
committed
Pick a different instance upon redirect (#5154)
The automatic instance redirection has the potential to pick the same instance the user is currently on. This is especially prevalent when the instance list is limited in number like how it is today. This PR checks the domain of the instance and ensures that it is not the same as the current instane before redirecting the user to it. Otherwise, it just sends the user to rediret.invidious.io
2 parents 3e32941 + a77f083 commit c5e9447

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/invidious/routes/misc.cr

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,17 @@ module Invidious::Routes::Misc
4242
referer = get_referer(env)
4343

4444
instance_list = Invidious::Jobs::InstanceListRefreshJob::INSTANCES["INSTANCES"]
45-
if instance_list.empty?
45+
# Filter out the current instance
46+
other_available_instances = instance_list.reject { |_, domain| domain == CONFIG.domain }
47+
48+
if other_available_instances.empty?
49+
# If the current instance is the only one, use the redirect URL as fallback
4650
instance_url = "redirect.invidious.io"
4751
else
52+
# Select other random instance
4853
# Sample returns an array
4954
# Instances are packaged as {region, domain} in the instance list
50-
instance_url = instance_list.sample(1)[0][1]
55+
instance_url = other_available_instances.sample(1)[0][1]
5156
end
5257

5358
env.redirect "https://#{instance_url}#{referer}"

0 commit comments

Comments
 (0)