support for numbered backends
Some checks are pending
Build and release container directly from master / release (push) Waiting to run
Invidious CI / build-docker (push) Waiting to run
Invidious CI / build - crystal: ${{ matrix.crystal }}, stable: ${{ matrix.stable }} (1.12.1, true) (push) Waiting to run
Invidious CI / build - crystal: ${{ matrix.crystal }}, stable: ${{ matrix.stable }} (1.13.2, true) (push) Waiting to run
Invidious CI / build - crystal: ${{ matrix.crystal }}, stable: ${{ matrix.stable }} (1.14.0, true) (push) Waiting to run
Invidious CI / build - crystal: ${{ matrix.crystal }}, stable: ${{ matrix.stable }} (1.15.0, true) (push) Waiting to run
Invidious CI / build - crystal: ${{ matrix.crystal }}, stable: ${{ matrix.stable }} (nightly, false) (push) Waiting to run
Invidious CI / build-docker-arm64 (push) Waiting to run
Invidious CI / lint (push) Waiting to run

This commit is contained in:
Fijxu 2025-03-31 18:41:17 -03:00
parent be9a3794e9
commit 015c9ec5d1
No known key found for this signature in database
GPG Key ID: 32C1DDF333EDA6A4
3 changed files with 53 additions and 32 deletions

View File

@ -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)

View File

@ -24,7 +24,16 @@ module Invidious::Routes::BeforeAll
extra_connect_csp = ""
if CONFIG.invidious_companion.present?
if env.request.cookies[CONFIG.server_id_cookie_name]?.nil?
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
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
@ -40,8 +49,9 @@ module Invidious::Routes::BeforeAll
end
env.set "current_companion", current_companion
end
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?

View File

@ -110,33 +110,43 @@
<%
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 %>
">•</span>
<% end %>
</a>
<% if !(index == CONFIG.invidious_companion.size-1) %>
<span> | </span>
<% end %>
<% end %>
<% 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>
<% end %>