From 1001a7229778793ed3ef461016a5b4f7688bbb96 Mon Sep 17 00:00:00 2001 From: Fijxu Date: Sun, 2 Mar 2025 16:35:44 -0300 Subject: [PATCH] feat: show status of the instance with a colored dot --- src/invidious/helpers/backend_info.cr | 45 +++++++++++++++++++++++++-- src/invidious/jobs/backend_checker.cr | 6 ++-- src/invidious/views/template.ecr | 14 ++++++++- 3 files changed, 58 insertions(+), 7 deletions(-) diff --git a/src/invidious/helpers/backend_info.cr b/src/invidious/helpers/backend_info.cr index ce8bb0d7..f982550b 100644 --- a/src/invidious/helpers/backend_info.cr +++ b/src/invidious/helpers/backend_info.cr @@ -1,16 +1,55 @@ module BackendInfo extend self @@exvpp_url : String = "" + @@status : Int32 = 0 - def get_videoplayback_proxy + def check_backends + check_videoplayback_proxy() + check_companion() + end + + def check_companion begin - response = HTTP::Client.get "#{CONFIG.invidious_companion.sample.private_url}/info" - exvpp_url = JSON.parse(response.body)["external_videoplayback_proxy"].to_s + response = HTTP::Client.get "#{CONFIG.invidious_companion.sample.private_url}/healthz" + if response.status_code == 200 + @@status = 1 + check_videoplayback_proxy() + else + @@status = 0 + end + rescue + @@status = 0 + end + end + + def check_videoplayback_proxy + begin + info = HTTP::Client.get "#{CONFIG.invidious_companion.sample.private_url}/info" + exvpp_url = JSON.parse(info.body)["external_videoplayback_proxy"]?.try &.to_s + exvpp_url = "" if exvpp_url.nil? @@exvpp_url = exvpp_url + if exvpp_url.empty? + @@status = 2 + return + else + begin + exvpp_health = HTTP::Client.get "#{exvpp_url}/health" + if exvpp_health.status_code == 200 + @@status = 2 + return + end + rescue + @@status = 1 + end + end rescue end end + def get_status + return @@status + end + def get_exvpp return @@exvpp_url end diff --git a/src/invidious/jobs/backend_checker.cr b/src/invidious/jobs/backend_checker.cr index 7b251947..1d48c78a 100644 --- a/src/invidious/jobs/backend_checker.cr +++ b/src/invidious/jobs/backend_checker.cr @@ -4,9 +4,9 @@ class Invidious::Jobs::CheckBackend < Invidious::Jobs::BaseJob def begin loop do - BackendInfo.get_videoplayback_proxy - LOGGER.info("Backend Checker: Done, sleeping for 60 seconds") - sleep 60.seconds + BackendInfo.check_backends + LOGGER.info("Backend Checker: Done, sleeping for 30 seconds") + sleep 30.seconds Fiber.yield end end diff --git a/src/invidious/views/template.ecr b/src/invidious/views/template.ecr index 620d26d4..b9504b52 100644 --- a/src/invidious/views/template.ecr +++ b/src/invidious/views/template.ecr @@ -3,6 +3,7 @@ dark_mode = env.get("preferences").as(Preferences).dark_mode current_backend = env.request.cookies[CONFIG.server_id_cookie_name]?.try &.value || env.request.headers["Host"] current_external_videoplayback_proxy = Invidious::HttpServer::Utils.get_external_proxy() + status = BackendInfo.get_status %> @@ -34,7 +35,18 @@