mirror of
https://git.nadeko.net/Fijxu/invidious.git
synced 2026-01-26 16:51:35 +00:00
feat: display if a backend is blocked
This commit is contained in:
@@ -238,6 +238,8 @@ class Config
|
||||
|
||||
property check_backends_interval : Int32 = 30
|
||||
|
||||
property check_backends_path : String = "/healthz"
|
||||
|
||||
property force_local : Bool = true
|
||||
|
||||
property disable_livestreams : Bool = true
|
||||
|
||||
@@ -3,7 +3,15 @@ module BackendInfo
|
||||
|
||||
enum Status
|
||||
Dead = 0
|
||||
Working = 1
|
||||
Blocked = 1
|
||||
Working = 2
|
||||
end
|
||||
|
||||
struct CompanionData
|
||||
include JSON::Serializable
|
||||
property blocked : Bool = false
|
||||
@[JSON::Field(key: "blockedCount")]
|
||||
property blocked_count : Int64 = 0
|
||||
end
|
||||
|
||||
@@status : Array(Int32) = Array.new(CONFIG.invidious_companion.size, Status::Dead.to_i)
|
||||
@@ -31,11 +39,27 @@ module BackendInfo
|
||||
begin
|
||||
client = HTTP::Client.new(companion.private_url)
|
||||
client.connect_timeout = 10.seconds
|
||||
response = client.get("/healthz")
|
||||
response = client.get(CONFIG.check_backends_path)
|
||||
if response.status_code == 200
|
||||
@@check_mutex.synchronize do
|
||||
updated_status[index] = Status::Working.to_i
|
||||
updated_ends.push(index)
|
||||
if response.content_type == "application/json"
|
||||
body = response.body
|
||||
status_json = CompanionData.from_json(body)
|
||||
if status_json.blocked
|
||||
@@check_mutex.synchronize do
|
||||
updated_status[index] = Status::Blocked.to_i
|
||||
updated_ends.push(index)
|
||||
end
|
||||
else
|
||||
@@check_mutex.synchronize do
|
||||
updated_status[index] = Status::Working.to_i
|
||||
updated_ends.push(index)
|
||||
end
|
||||
end
|
||||
else
|
||||
@@check_mutex.synchronize do
|
||||
updated_status[index] = Status::Working.to_i
|
||||
updated_ends.push(index)
|
||||
end
|
||||
end
|
||||
generate_csp([companion.public_url, companion.i2p_public_url], index)
|
||||
else
|
||||
|
||||
@@ -125,6 +125,7 @@
|
||||
<%= HTML.escape(CONFIG.backend_name_prefix + (index + 1).to_s) %> <%= HTML.escape(companion.note) %>
|
||||
<span style="color:
|
||||
<% if status[index] == BackendInfo::Status::Dead.to_i %> #fd4848; <% end %>
|
||||
<% if status[index] == BackendInfo::Status::Blocked.to_i %> #ddc338; <% end %>
|
||||
<% if status[index] == BackendInfo::Status::Working.to_i %> #42ae3c; <% end %>
|
||||
">•</span>
|
||||
</a>
|
||||
@@ -139,6 +140,7 @@
|
||||
<%= HTML.escape(CONFIG.backend_name_prefix + (index + 1).to_s) %> <%= HTML.escape(companion.note) %>
|
||||
<span style="color:
|
||||
<% if status[index] == BackendInfo::Status::Dead.to_i %> #fd4848; <% end %>
|
||||
<% if status[index] == BackendInfo::Status::Blocked.to_i %> #ddc338; <% end %>
|
||||
<% if status[index] == BackendInfo::Status::Working.to_i %> #42ae3c; <% end %>
|
||||
">•</span>
|
||||
</a>
|
||||
|
||||
Reference in New Issue
Block a user