companion: use array of domains to support Tor and I2P domains

This commit is contained in:
Fijxu 2025-04-03 23:08:27 -03:00
parent a77a272935
commit 0bb37e4156
Signed by: Fijxu
GPG key ID: 32C1DDF333EDA6A4
3 changed files with 10 additions and 11 deletions

View file

@ -84,7 +84,7 @@ class Config
property public_url : URI = URI.parse("")
property note : String = ""
property domain : String = ""
property domain : Array(String) = [] of String
end
# Number of threads to use for crawling videos from channels (for updating subscriptions)

View file

@ -25,9 +25,9 @@ module Invidious::Routes::BeforeAll
if CONFIG.invidious_companion.present?
CONFIG.invidious_companion.each_with_index do |companion, index|
if companion.domain == env.request.headers["Host"]
if companion.domain.includes?(env.request.headers["Host"])
env.set "current_companion", index
env.set "domain", true
env.set "using_numbered_backend", true
break
end
end

View file

@ -109,16 +109,15 @@
<%
if CONFIG.invidious_companion.present?
current_backend = env.get?("current_companion").try &.as(Int32)
domain = env.get?("domain").try &.as(Bool)
using_numbered_backend = env.get?("using_numbered_backend").try &.as(Bool)
status = BackendInfo.get_status
%>
<div class="h-box" style="margin-bottom: 10px;">
<b>Switch Backend:</b>
<% if domain %>
<% if using_numbered_backend %>
<b>Switch Backend (Numbered):</b>
<% scheme = env.request.headers["X-Forwarded-Proto"]? || ("https" if CONFIG.https_only) || "http" %>
<% 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;">
<a href="<%= scheme %>://<%= companion.domain %><%= env.request.resource %>" style="<%= 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 %>
@ -131,9 +130,9 @@
<% end %>
<% end %>
<% else %>
<b>Switch Backend:</b>
<% 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;">
<a href="/switchbackend?backend_id=<%= index.to_s %>" style="<%= 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 %>