feat: show status of the instance with a colored dot
All checks were successful
Invidious CI / build (push) Successful in 5m9s

This commit is contained in:
Fijxu 2025-03-02 16:35:44 -03:00
parent e5c0f15398
commit 1001a72297
Signed by: Fijxu
GPG key ID: 32C1DDF333EDA6A4
3 changed files with 58 additions and 7 deletions

View file

@ -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

View file

@ -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

View file

@ -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
%>
<!DOCTYPE html>
<html lang="<%= locale %>">
@ -34,7 +35,18 @@
<div class="pure-g navbar h-box">
<% if navbar_search %>
<div class="pure-u-1 pure-u-md-4-24">
<a href="/" class="index-link pure-menu-heading">Invidious</a>
<a href="/" class="index-link pure-menu-heading">
Invidious
<% if status == 0 %>
<span style="color: #fd4848;">•</span>
<% end %>
<% if status == 1 %>
<span style="color: #d06925;">•</span>
<% end %>
<% if status == 2 %>
<span style="color: #42ae3c;">•</span>
<% end %>
</a>
</div>
<div class="pure-u-1 pure-u-md-12-24 searchbar">
<% autofocus = false %><%= rendered "components/search_box" %>