support for numbered backends
All checks were successful
Invidious CI / build (push) Successful in 6m3s
All checks were successful
Invidious CI / build (push) Successful in 6m3s
This commit is contained in:
parent
be9a3794e9
commit
015c9ec5d1
3 changed files with 53 additions and 32 deletions
|
@ -84,6 +84,7 @@ class Config
|
|||
property public_url : URI = URI.parse("")
|
||||
|
||||
property note : String = ""
|
||||
property domain : String = ""
|
||||
end
|
||||
|
||||
# Number of threads to use for crawling videos from channels (for updating subscriptions)
|
||||
|
|
|
@ -24,24 +24,34 @@ module Invidious::Routes::BeforeAll
|
|||
extra_connect_csp = ""
|
||||
|
||||
if CONFIG.invidious_companion.present?
|
||||
if env.request.cookies[CONFIG.server_id_cookie_name]?.nil?
|
||||
env.response.cookies[CONFIG.server_id_cookie_name] = Invidious::User::Cookies.server_id(env.request.headers["Host"])
|
||||
CONFIG.invidious_companion.each_with_index do |companion, index|
|
||||
if companion.domain == env.request.headers["Host"]
|
||||
env.set "current_companion", index
|
||||
env.set "domain", true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
begin
|
||||
current_companion = env.request.cookies[CONFIG.server_id_cookie_name].value.try &.to_i
|
||||
rescue
|
||||
current_companion = rand(CONFIG.invidious_companion.size)
|
||||
if env.get?("current_companion").try &.as(Int32) == nil
|
||||
if !env.request.cookies[CONFIG.server_id_cookie_name]?
|
||||
env.response.cookies[CONFIG.server_id_cookie_name] = Invidious::User::Cookies.server_id(env.request.headers["Host"])
|
||||
end
|
||||
|
||||
begin
|
||||
current_companion = env.request.cookies[CONFIG.server_id_cookie_name].value.try &.to_i
|
||||
rescue
|
||||
current_companion = rand(CONFIG.invidious_companion.size)
|
||||
end
|
||||
|
||||
if current_companion > CONFIG.invidious_companion.size
|
||||
current_companion = current_companion % CONFIG.invidious_companion.size
|
||||
env.response.cookies[CONFIG.server_id_cookie_name] = Invidious::User::Cookies.server_id(env.request.headers["Host"], current_companion)
|
||||
end
|
||||
|
||||
env.set "current_companion", current_companion
|
||||
end
|
||||
|
||||
if current_companion > CONFIG.invidious_companion.size
|
||||
current_companion = current_companion % CONFIG.invidious_companion.size
|
||||
env.response.cookies[CONFIG.server_id_cookie_name] = Invidious::User::Cookies.server_id(env.request.headers["Host"], current_companion)
|
||||
end
|
||||
|
||||
env.set "current_companion", current_companion
|
||||
|
||||
extra_media_csp, extra_connect_csp = BackendInfo.get_csp()
|
||||
extra_media_csp, extra_connect_csp = BackendInfo.get_csp
|
||||
end
|
||||
|
||||
if !CONFIG.external_videoplayback_proxy.empty?
|
||||
|
|
|
@ -110,31 +110,41 @@
|
|||
<%
|
||||
if CONFIG.invidious_companion.present?
|
||||
current_backend = env.get("current_companion").as(Int32)
|
||||
domain = env.get?("domain").try &.as(Bool)
|
||||
status = BackendInfo.get_status
|
||||
%>
|
||||
<div class="h-box" style="margin-bottom: 10px;">
|
||||
<b>Switch Backend:</b>
|
||||
<% CONFIG.invidious_companion.each_with_index do | backend, index | %>
|
||||
<% if current_backend == index %>
|
||||
<a href="/switchbackend?backend_id=<%= index.to_s %>" style="text-decoration-line: underline; display: inline-block;">
|
||||
Backend<%= HTML.escape((index+1).to_s) %> <%= HTML.escape(backend.note) %>
|
||||
<% if domain %>
|
||||
<% CONFIG.invidious_companion.each_with_index do | companion, index | %>
|
||||
<% is_current_backend_host = companion.domain == env.request.headers["Host"] %>
|
||||
<% scheme = env.request.headers["X-Forwarded-Proto"]? || ("https" if CONFIG.https_only) || "http" %>
|
||||
<a href="<%= scheme %>://<%= companion.domain %><%= env.request.resource %>" style="<%= is_current_backend_host ? "text-decoration-line: underline;" : "" %> display: inline-block;">
|
||||
Backend<%= HTML.escape((index + 1).to_s) %> <%= HTML.escape(companion.note) %>
|
||||
<span style="color:
|
||||
<% if status[index] == 0 %> #fd4848; <% end %>
|
||||
<% if status[index] == 1 %> #d06925; <% end %>
|
||||
<% if status[index] == 2 %> #42ae3c; <% end %>
|
||||
">•</span>
|
||||
<% else %>
|
||||
<a href="/switchbackend?backend_id=<%= index.to_s %>" style="display: inline-block;">
|
||||
Backend<%= HTML.escape((index+1).to_s) %> <%= HTML.escape(backend.note) %>
|
||||
<span style="color:
|
||||
<% if status[index] == 0 %> #fd4848; <% end %>
|
||||
<% if status[index] == 1 %> #d06925; <% end %>
|
||||
<% if status[index] == 2 %> #42ae3c; <% end %>
|
||||
<% if status[index] == 0 %> #fd4848; <% end %>
|
||||
<% if status[index] == 1 %> #d06925; <% end %>
|
||||
<% if status[index] == 2 %> #42ae3c; <% end %>
|
||||
">•</span>
|
||||
</a>
|
||||
<% if !(index == CONFIG.invidious_companion.size-1) %>
|
||||
<span> | </span>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</a>
|
||||
<% if !(index == CONFIG.invidious_companion.size-1) %>
|
||||
<span> | </span>
|
||||
<% else %>
|
||||
<% CONFIG.invidious_companion.each_with_index do | companion, index | %>
|
||||
<% is_current_backend_index = current_backend == index %>
|
||||
<a href="/switchbackend?backend_id=<%= index.to_s %>" style="<%= is_current_backend_index ? "text-decoration-line: underline;" : "" %> display: inline-block;">
|
||||
Backend<%= HTML.escape((index + 1).to_s) %> <%= HTML.escape(companion.note) %>
|
||||
<span style="color:
|
||||
<% if status[index] == 0 %> #fd4848; <% end %>
|
||||
<% if status[index] == 1 %> #d06925; <% end %>
|
||||
<% if status[index] == 2 %> #42ae3c; <% end %>
|
||||
">•</span>
|
||||
</a>
|
||||
<% if !(index == CONFIG.invidious_companion.size-1) %>
|
||||
<span> | </span>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Reference in a new issue