External Proxies: Adapt it to use a NamedTuple

This commit is contained in:
Fijxu 2024-10-31 21:38:40 -03:00
parent 67998d1f36
commit fc910b43ba
Signed by: Fijxu
GPG key ID: 32C1DDF333EDA6A4
3 changed files with 10 additions and 7 deletions

View file

@ -390,7 +390,7 @@ def gen_videoplayback_proxy_list
if !CONFIG.external_videoplayback_proxy.empty? if !CONFIG.external_videoplayback_proxy.empty?
external_videoplayback_proxy = "" external_videoplayback_proxy = ""
CONFIG.external_videoplayback_proxy.each do |proxy| CONFIG.external_videoplayback_proxy.each do |proxy|
external_videoplayback_proxy += " #{proxy}" external_videoplayback_proxy += " #{proxy[:url]}"
end end
else else
external_videoplayback_proxy = "" external_videoplayback_proxy = ""

View file

@ -9,16 +9,19 @@ module Invidious::HttpServer
def check_external_proxy def check_external_proxy
CONFIG.external_videoplayback_proxy.each do |proxy| CONFIG.external_videoplayback_proxy.each do |proxy|
begin begin
response = HTTP::Client.get(proxy) response = HTTP::Client.get("#{proxy[:url]}/health")
if response.status_code == 200 if response.status_code == 200
@@proxy_alive = proxy @@proxy_alive = proxy[:url]
LOGGER.debug("CheckExternalProxy: Proxy set to: '#{proxy}'") LOGGER.debug("CheckExternalProxy: Proxy set to: '#{proxy[:url]}'")
break break
end end
rescue rescue
LOGGER.debug("CheckExternalProxy: Proxy '#{proxy}' is not available") LOGGER.debug("CheckExternalProxy: Proxy '#{proxy[:url]}' is not available")
end end
end end
if @@proxy_alive.empty?
LOGGER.warn("CheckExternalProxy: No proxies alive! Using own server proxy")
end
end end
def get_external_proxy def get_external_proxy

View file

@ -5,8 +5,8 @@ class Invidious::Jobs::CheckExternalProxy < Invidious::Jobs::BaseJob
def begin def begin
loop do loop do
HttpServer::Utils.check_external_proxy HttpServer::Utils.check_external_proxy
LOGGER.info("CheckExternalProxy: Done, sleeping for 1 minute") LOGGER.info("CheckExternalProxy: Done, sleeping for 10 seconds")
sleep 1.minutes sleep 10.seconds
Fiber.yield Fiber.yield
end end
end end