diff options
| author | syeopite <syeopite@syeopite.dev> | 2025-02-26 14:05:21 -0800 |
|---|---|---|
| committer | syeopite <syeopite@syeopite.dev> | 2025-02-26 14:05:21 -0800 |
| commit | c5e9447f41735a3c2de13a6ae8ec80ef7800b06c (patch) | |
| tree | 0b0dfa8bf60e8ff62e085bafc46fce0a578a2146 /src | |
| parent | 3e329410d1f6426f49d0df425b31e78e9503bd9d (diff) | |
| parent | a77f083a0ab6d018023791d113cfbf97a05f315d (diff) | |
| download | invidious-c5e9447f41735a3c2de13a6ae8ec80ef7800b06c.tar.gz invidious-c5e9447f41735a3c2de13a6ae8ec80ef7800b06c.tar.bz2 invidious-c5e9447f41735a3c2de13a6ae8ec80ef7800b06c.zip | |
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
Diffstat (limited to 'src')
| -rw-r--r-- | src/invidious/routes/misc.cr | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/invidious/routes/misc.cr b/src/invidious/routes/misc.cr index 8b620d63..0b868755 100644 --- a/src/invidious/routes/misc.cr +++ b/src/invidious/routes/misc.cr @@ -42,12 +42,17 @@ module Invidious::Routes::Misc referer = get_referer(env) instance_list = Invidious::Jobs::InstanceListRefreshJob::INSTANCES["INSTANCES"] - if instance_list.empty? + # Filter out the current instance + other_available_instances = instance_list.reject { |_, domain| domain == CONFIG.domain } + + if other_available_instances.empty? + # If the current instance is the only one, use the redirect URL as fallback instance_url = "redirect.invidious.io" else + # Select other random instance # Sample returns an array # Instances are packaged as {region, domain} in the instance list - instance_url = instance_list.sample(1)[0][1] + instance_url = other_available_instances.sample(1)[0][1] end env.redirect "https://#{instance_url}#{referer}" |
