Fix logic of this shit again

This commit is contained in:
Fijxu
2026-01-30 21:43:25 -03:00
parent 9107f22720
commit 9ab8d39168
3 changed files with 19 additions and 2 deletions

View File

@@ -119,7 +119,13 @@ class CompanionStatus
client = HTTP::Client.new(companion.private_url, tls: tls)
client.connect_timeout = 10.seconds
response = client.get(CONFIG.check_backends_path)
begin
response = client.get(CONFIG.check_backends_path)
rescue
@companions[index].status = Status::Down
return
end
if response.status_code == 200
if response.content_type == "application/json"
body = response.body

View File

@@ -181,11 +181,13 @@ module Invidious::Routes::BeforeAll::Companion
else
# Set cookie if there is no cookie
if !env.request.cookies.has_key?("PREFS")
current_companion = get_companion(preferences)
current_companion = self.find_available_companion(env, host, nil, companion_status, preferences)
if current_companion
self.set_companion(env, preferences, host, current_companion)
else
return ""
current_companion = rand(c_size)
self.set_companion(env, preferences, host, current_companion)
end
else
begin

View File

@@ -12,6 +12,7 @@ module Invidious::Routes::PreferencesRoute
def self.update(env)
locale = env.get("preferences").as(Preferences).locale
preferences = env.get("preferences").as(Preferences)
referer = get_referer(env)
video_loop = env.params.body["video_loop"]?.try &.as(String)
@@ -176,6 +177,12 @@ module Invidious::Routes::PreferencesRoute
show_community_backends ||= "off"
show_community_backends = show_community_backends == "on"
current_companion = preferences.current_companion
search_privacy = env.params.body["search_privacy"]?.try &.as(String)
search_privacy ||= "off"
search_privacy = search_privacy == "on"
# Convert to JSON and back again to take advantage of converters used for compatibility
preferences = Preferences.from_json({
annotations: annotations,
@@ -216,6 +223,8 @@ module Invidious::Routes::PreferencesRoute
hidden_channels: hidden_channels,
default_trending_type: default_trending_type,
show_community_backends: show_community_backends,
current_companion: current_companion,
search_privacy: search_privacy,
}.to_json)
if user = env.get? "user"