From fc910b43baf93efe1422f29d2eae7b12a1e4ffc4 Mon Sep 17 00:00:00 2001 From: Fijxu Date: Thu, 31 Oct 2024 21:38:40 -0300 Subject: [PATCH] External Proxies: Adapt it to use a NamedTuple --- src/invidious/helpers/utils.cr | 2 +- src/invidious/http_server/utils.cr | 11 +++++++---- src/invidious/jobs/check_external_proxy.cr | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/invidious/helpers/utils.cr b/src/invidious/helpers/utils.cr index c95532a1..a067b142 100644 --- a/src/invidious/helpers/utils.cr +++ b/src/invidious/helpers/utils.cr @@ -390,7 +390,7 @@ def gen_videoplayback_proxy_list if !CONFIG.external_videoplayback_proxy.empty? external_videoplayback_proxy = "" CONFIG.external_videoplayback_proxy.each do |proxy| - external_videoplayback_proxy += " #{proxy}" + external_videoplayback_proxy += " #{proxy[:url]}" end else external_videoplayback_proxy = "" diff --git a/src/invidious/http_server/utils.cr b/src/invidious/http_server/utils.cr index eecfb1cc..89c0beb2 100644 --- a/src/invidious/http_server/utils.cr +++ b/src/invidious/http_server/utils.cr @@ -9,16 +9,19 @@ module Invidious::HttpServer def check_external_proxy CONFIG.external_videoplayback_proxy.each do |proxy| begin - response = HTTP::Client.get(proxy) + response = HTTP::Client.get("#{proxy[:url]}/health") if response.status_code == 200 - @@proxy_alive = proxy - LOGGER.debug("CheckExternalProxy: Proxy set to: '#{proxy}'") + @@proxy_alive = proxy[:url] + LOGGER.debug("CheckExternalProxy: Proxy set to: '#{proxy[:url]}'") break end rescue - LOGGER.debug("CheckExternalProxy: Proxy '#{proxy}' is not available") + LOGGER.debug("CheckExternalProxy: Proxy '#{proxy[:url]}' is not available") end end + if @@proxy_alive.empty? + LOGGER.warn("CheckExternalProxy: No proxies alive! Using own server proxy") + end end def get_external_proxy diff --git a/src/invidious/jobs/check_external_proxy.cr b/src/invidious/jobs/check_external_proxy.cr index 7a4a2080..6924d50c 100644 --- a/src/invidious/jobs/check_external_proxy.cr +++ b/src/invidious/jobs/check_external_proxy.cr @@ -5,8 +5,8 @@ class Invidious::Jobs::CheckExternalProxy < Invidious::Jobs::BaseJob def begin loop do HttpServer::Utils.check_external_proxy - LOGGER.info("CheckExternalProxy: Done, sleeping for 1 minute") - sleep 1.minutes + LOGGER.info("CheckExternalProxy: Done, sleeping for 10 seconds") + sleep 10.seconds Fiber.yield end end