diff --git a/locales/en-US.json b/locales/en-US.json index 13cd9a48..ae151992 100644 --- a/locales/en-US.json +++ b/locales/en-US.json @@ -528,5 +528,6 @@ "username_required_field": "Username is a required field", "username_empty": "Username cannot be empty", "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" } diff --git a/locales/es.json b/locales/es.json index 89afdd4b..9dd479ee 100644 --- a/locales/es.json +++ b/locales/es.json @@ -518,5 +518,6 @@ "carousel_go_to": "Ir a la diapositiva `x`", "footer_contact_url": "Contactar al Administrador", "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" } diff --git a/src/invidious/routes/before_all.cr b/src/invidious/routes/before_all.cr index 9caffb3d..4d23db6f 100644 --- a/src/invidious/routes/before_all.cr +++ b/src/invidious/routes/before_all.cr @@ -48,6 +48,17 @@ module Invidious::Routes::BeforeAll env.response.cookies[CONFIG.server_id_cookie_name] = Invidious::User::Cookies.server_id(host, current_companion) 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 if host.split(".").last == "i2p" diff --git a/src/invidious/views/template.ecr b/src/invidious/views/template.ecr index 515a8836..cb08968c 100644 --- a/src/invidious/views/template.ecr +++ b/src/invidious/views/template.ecr @@ -112,6 +112,7 @@ domain = env.get?("using_domain") scheme = env.get("scheme") status = BackendInfo.get_status + companion_switched = env.get?("companion_switched") %>
Switch Backend: @@ -149,6 +150,12 @@
<% end %> + <% if companion_switched %> +
+

<%= translate(locale, "backend_unavailable") %>

+
+ <% end %> + <% if CONFIG.banner %>

<%= CONFIG.banner %>