mirror of
https://git.nadeko.net/Fijxu/invidious.git
synced 2025-12-15 01:25:08 +00:00
feat(backends): redirect to another backend if one is unavailable
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:
@@ -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"
|
||||
|
||||
@@ -112,6 +112,7 @@
|
||||
domain = env.get?("using_domain")
|
||||
scheme = env.get("scheme")
|
||||
status = BackendInfo.get_status
|
||||
companion_switched = env.get?("companion_switched")
|
||||
%>
|
||||
<div class="h-box" style="margin-bottom: 10px;">
|
||||
<b>Switch Backend:</b>
|
||||
@@ -149,6 +150,12 @@
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if companion_switched %>
|
||||
<div class="h-box">
|
||||
<p><%= translate(locale, "backend_unavailable") %></p>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if CONFIG.banner %>
|
||||
<div class="h-box">
|
||||
<h3><%= CONFIG.banner %></h3>
|
||||
|
||||
Reference in New Issue
Block a user