feat: add support for community backends (volunteers that host invidious companion for the instance)

This commit is contained in:
Fijxu
2026-01-01 21:46:50 -03:00
parent 6655d1a56c
commit 6027bb04ec
8 changed files with 27 additions and 0 deletions

View File

@@ -59,6 +59,7 @@ struct ConfigPreferences
property hidden_channels : Array(String)? = nil
@[YAML::Field(ignore: true)]
property default_trending_type : Invidious::Routes::Feeds::TrendingTypes = Invidious::Routes::Feeds::TrendingTypes::Default
property show_community_backends : Bool = false
def to_tuple
{% begin %}
@@ -95,6 +96,7 @@ class Config
property note : String = ""
property domain : Array(String) = [] of String
property community : Bool = false
# Indicates if this companion instance uses the built-in proxy
property builtin_proxy : Bool = false

View File

@@ -172,6 +172,10 @@ module Invidious::Routes::PreferencesRoute
default_trending_type = env.params.body["default_trending_type"]?.try &.as(String)
default_trending_type ||= Invidious::Routes::Feeds::TrendingTypes::Default
show_community_backends = env.params.body["show_community_backends"]?.try &.as(String)
show_community_backends ||= "off"
show_community_backends= show_community_backends == "on"
# Convert to JSON and back again to take advantage of converters used for compatibility
preferences = Preferences.from_json({
annotations: annotations,
@@ -211,6 +215,7 @@ module Invidious::Routes::PreferencesRoute
default_playlist: default_playlist,
hidden_channels: hidden_channels,
default_trending_type: default_trending_type,
show_community_backends: show_community_backends,
}.to_json)
if user = env.get? "user"

View File

@@ -59,6 +59,7 @@ struct Preferences
property hidden_channels : Array(String)? = nil
property default_trending_type : Invidious::Routes::Feeds::TrendingTypes = Invidious::Routes::Feeds::TrendingTypes::Default
property default_playlist : String? = nil
property show_community_backends : Bool = false
module BoolToString
def self.to_json(value : String, json : JSON::Builder)

View File

@@ -119,6 +119,7 @@
<b>Switch Backend:</b>
<% if domain %>
<% CONFIG.invidious_companion.each_with_index do | companion, index | %>
<% next if companion.community && !preferences.show_community_backends %>
<% host_backend = env.request.headers["Host"].sub(/([^.]+)(\d+)/, "\\1#{index+1}") %>
<% is_current_backend_host = host_backend == env.request.headers["Host"] %>
<a href="<%= scheme %>://<%= host_backend %><%= env.request.resource %>" style="<%= is_current_backend_host ? "text-decoration-line: underline;" : "" %> display: inline-block;">
@@ -136,6 +137,7 @@
<% else %>
<% current_page = env.get("current_page") %>
<% CONFIG.invidious_companion.each_with_index do | companion, index | %>
<% next if companion.community && !preferences.show_community_backends %>
<a href="/switchbackend?backend_id=<%= index.to_s %>&referer=<%= current_page %>" style="<%= current_backend == index ? "text-decoration-line: underline;" : "" %> display: inline-block;">
<%= HTML.escape(CONFIG.backend_name_prefix + (index + 1).to_s) %> <%= HTML.escape(companion.note) %>
<span style="color:

View File

@@ -235,6 +235,12 @@
<input name="automatic_instance_redirect" id="automatic_instance_redirect" type="checkbox" <% if preferences.automatic_instance_redirect %>checked<% end %>>
</div>
<div class="pure-control-group">
<label for="show_community_backends"><%= translate(locale, "preferences_show_community_backends_label") %></label>
<input name="show_community_backends" id="show_community_backends" type="checkbox" <% if preferences.show_community_backends %>checked<% end %>>
<span class="preference-description"><%= translate(locale, "preferences_show_community_backends_description") %></span>
</div>
<div class="pure-control-group">
<label for="hidden_channels"><%= translate(locale, "preferences_hidden_channels") %></label>
<% hidden_channels = preferences.hidden_channels %>