From 9ab8d391688bff863321d961f7302c1596fbf584 Mon Sep 17 00:00:00 2001 From: Fijxu Date: Fri, 30 Jan 2026 21:43:25 -0300 Subject: [PATCH] Fix logic of this shit again --- src/invidious/helpers/companion_status.cr | 8 +++++++- src/invidious/routes/before_all.cr | 4 +++- src/invidious/routes/preferences.cr | 9 +++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/invidious/helpers/companion_status.cr b/src/invidious/helpers/companion_status.cr index 50eccffb..29783f81 100644 --- a/src/invidious/helpers/companion_status.cr +++ b/src/invidious/helpers/companion_status.cr @@ -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 diff --git a/src/invidious/routes/before_all.cr b/src/invidious/routes/before_all.cr index fcfc3345..1ad25812 100644 --- a/src/invidious/routes/before_all.cr +++ b/src/invidious/routes/before_all.cr @@ -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 diff --git a/src/invidious/routes/preferences.cr b/src/invidious/routes/preferences.cr index 55ffaff6..0a8135af 100644 --- a/src/invidious/routes/preferences.cr +++ b/src/invidious/routes/preferences.cr @@ -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"