<%= translate(locale, "companion_switch_backend") %>
<% if domain %>
- <% CONFIG.invidious_companion.each_with_index do | companion, index | %>
- <% next if companion.community && !preferences.show_community_backends %>
- <% next if companion.i2p_public_url.host.nil? && using_i2p %>
- <% host_backend = env.request.headers["Host"].sub(/([^.]+)(\d+)/, "\\1#{index+1}") %>
- <% is_current_backend_host = host_backend == env.request.headers["Host"] %>
+ <% CONFIG.invidious_companion.each_with_index do | companion, index |
+ next if companion.community && !preferences.show_community_backends
+ next if companion.i2p_public_url.host.nil? && using_i2p
+ host_backend = env.request.headers["Host"].sub(/([^.]+)(\d+)/, "\\1#{index+1}")
+ is_current_backend_host = host_backend == env.request.headers["Host"]
+ backend_name_prefix = CONFIG.backend_name_prefix + (index + 1).to_s
+ %>
display: inline-block;">
- <%= HTML.escape(CONFIG.backend_name_prefix + (index + 1).to_s) %> <%= HTML.escape(companion.note) %>
+ <%= HTML.escape(backend_name_prefix) %> <%= HTML.escape(companion.note) %>
❚
<% if !(index == CONFIG.invidious_companion.size-1) %>
@@ -137,16 +139,19 @@
<% end %>
<% end %>
<% else %>
- <% current_page = env.get("current_page") %>
- <% CONFIG.invidious_companion.each_with_index do | companion, index | %>
- <% next if companion.community && !preferences.show_community_backends %>
- <% next if companion.i2p_public_url.host.nil? && using_i2p %>
+ <%
+ current_page = env.get("current_page")
+ CONFIG.invidious_companion.each_with_index do | companion, index |
+ next if companion.community && !preferences.show_community_backends
+ next if companion.i2p_public_url.host.nil? && using_i2p
+ backend_name_prefix = CONFIG.backend_name_prefix + (index + 1).to_s
+ %>
display: inline-block;">
- <%= HTML.escape(CONFIG.backend_name_prefix + (index + 1).to_s) %> <%= HTML.escape(companion.note) %>
+ <%= HTML.escape(backend_name_prefix) %> <%= HTML.escape(companion.note) %>
❚
<% if !(index == CONFIG.invidious_companion.size-1) %>
@@ -342,7 +347,7 @@
<%
if CONFIG.invidious_companion.present?
- companion_public_url = env.get("companion_public_url").as(String)
+ companion_public_url = env.get("companion_companion_public_url").as(String)
%>
You are currently using Backend: <%= current_backend ? companion_public_url : "Unable to get backend, this is bug, please report it!" %>
<% end %>
diff --git a/src/invidious/yt_backend/youtube_api.cr b/src/invidious/yt_backend/youtube_api.cr
index aab7a979..47d30961 100644
--- a/src/invidious/yt_backend/youtube_api.cr
+++ b/src/invidious/yt_backend/youtube_api.cr
@@ -652,19 +652,23 @@ module YoutubeAPI
# Send the POST request
begin
- if env.nil?
- working_ends = BackendInfo.get_working_ends
- current_companion = working_ends.sample
- else
- current_companion = env.get("current_companion").as(Int32)
+ if companion_status = COMPANION_STATUS
+ if env.nil?
+ working_ends = companion_status.working_companions.community
+ current_companion = working_ends.sample
+ else
+ current_companion = env.get("current_companion").as(Int32)
+ end
end
response_body = Hash(String, JSON::Any).new
- COMPANION_POOL[current_companion].client do |wrapper|
- companion_base_url = wrapper.companion.private_url.path
+ if current_companion
+ COMPANION_POOL[current_companion].client do |wrapper|
+ companion_base_url = wrapper.companion.private_url.path
- wrapper.client.post("#{companion_base_url}#{endpoint}", headers: headers, body: data.to_json) do |response|
- response_body = JSON.parse(response.body_io).as_h
+ wrapper.client.post("#{companion_base_url}#{endpoint}", headers: headers, body: data.to_json) do |response|
+ response_body = JSON.parse(response.body_io).as_h
+ end
end
end