feat(backends): redirect to another backend if one is unavailable
Some checks failed
Invidious CI / build (push) Has been cancelled

Only works with cookies for now. Support for numbered backends will be
added later since it requires some black magic.
This commit is contained in:
Fijxu 2025-04-14 16:53:09 -04:00
parent e13800e859
commit ad95f0e2c0
Signed by: Fijxu
GPG key ID: 32C1DDF333EDA6A4
4 changed files with 22 additions and 2 deletions

View file

@ -528,5 +528,6 @@
"username_required_field": "Username is a required field", "username_required_field": "Username is a required field",
"username_empty": "Username cannot be empty", "username_empty": "Username cannot be empty",
"username_is_the_same": "This is your username, use another one", "username_is_the_same": "This is your username, use another one",
"username_taken": "Username is already taken, use another one" "username_taken": "Username is already taken, use another one",
"backend_unavailable": "The backend you selected is unavailable. You have been redirected to the next one"
} }

View file

@ -518,5 +518,6 @@
"carousel_go_to": "Ir a la diapositiva `x`", "carousel_go_to": "Ir a la diapositiva `x`",
"footer_contact_url": "Contactar al Administrador", "footer_contact_url": "Contactar al Administrador",
"preferences_preload_label": "Precargar datos del vídeo: ", "preferences_preload_label": "Precargar datos del vídeo: ",
"Filipino (auto-generated)": "Filipino (generado automáticamente)" "Filipino (auto-generated)": "Filipino (generado automáticamente)",
"backend_unavailable": "El backend seleccionado no está disponible. Has sido redireccionado al siguiente"
} }

View file

@ -48,6 +48,17 @@ module Invidious::Routes::BeforeAll
env.response.cookies[CONFIG.server_id_cookie_name] = Invidious::User::Cookies.server_id(host, current_companion) env.response.cookies[CONFIG.server_id_cookie_name] = Invidious::User::Cookies.server_id(host, current_companion)
end end
companion_status = BackendInfo.get_status
if companion_status[current_companion] != 2
alive_companion = companion_status.index(2)
if alive_companion
env.set "companion_switched", true
current_companion = alive_companion
env.response.cookies[CONFIG.server_id_cookie_name] = Invidious::User::Cookies.server_id(host, current_companion)
end
end
env.set "current_companion", current_companion env.set "current_companion", current_companion
if host.split(".").last == "i2p" if host.split(".").last == "i2p"

View file

@ -112,6 +112,7 @@
domain = env.get?("using_domain") domain = env.get?("using_domain")
scheme = env.get("scheme") scheme = env.get("scheme")
status = BackendInfo.get_status status = BackendInfo.get_status
companion_switched = env.get?("companion_switched")
%> %>
<div class="h-box" style="margin-bottom: 10px;"> <div class="h-box" style="margin-bottom: 10px;">
<b>Switch Backend:</b> <b>Switch Backend:</b>
@ -149,6 +150,12 @@
</div> </div>
<% end %> <% end %>
<% if companion_switched %>
<div class="h-box">
<p><%= translate(locale, "backend_unavailable") %></p>
</div>
<% end %>
<% if CONFIG.banner %> <% if CONFIG.banner %>
<div class="h-box"> <div class="h-box">
<h3><%= CONFIG.banner %></h3> <h3><%= CONFIG.banner %></h3>