mirror of
https://git.nadeko.net/Fijxu/invidious.git
synced 2026-01-20 22:01:40 +00:00
feat: display if a backend is blocked
This commit is contained in:
@@ -1181,6 +1181,17 @@ video_cache:
|
|||||||
##
|
##
|
||||||
#check_backends_interval: true
|
#check_backends_interval: true
|
||||||
|
|
||||||
|
##
|
||||||
|
## The endpoint to check if a backend is alive or not.
|
||||||
|
## If using a the nadeko.net Invidious companion patches you can set it to
|
||||||
|
## "/status" to check if the Invidious companion instance that is being checked
|
||||||
|
## is blocked by youtube.
|
||||||
|
##
|
||||||
|
## Accepted values: a string
|
||||||
|
## Default: "/healthz"
|
||||||
|
##
|
||||||
|
#check_backends_path: "/healthz"
|
||||||
|
|
||||||
##
|
##
|
||||||
## Forces the video proxy.
|
## Forces the video proxy.
|
||||||
##
|
##
|
||||||
|
|||||||
@@ -238,6 +238,8 @@ class Config
|
|||||||
|
|
||||||
property check_backends_interval : Int32 = 30
|
property check_backends_interval : Int32 = 30
|
||||||
|
|
||||||
|
property check_backends_path : String = "/healthz"
|
||||||
|
|
||||||
property force_local : Bool = true
|
property force_local : Bool = true
|
||||||
|
|
||||||
property disable_livestreams : Bool = true
|
property disable_livestreams : Bool = true
|
||||||
|
|||||||
@@ -3,7 +3,15 @@ module BackendInfo
|
|||||||
|
|
||||||
enum Status
|
enum Status
|
||||||
Dead = 0
|
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
|
end
|
||||||
|
|
||||||
@@status : Array(Int32) = Array.new(CONFIG.invidious_companion.size, Status::Dead.to_i)
|
@@status : Array(Int32) = Array.new(CONFIG.invidious_companion.size, Status::Dead.to_i)
|
||||||
@@ -31,11 +39,27 @@ module BackendInfo
|
|||||||
begin
|
begin
|
||||||
client = HTTP::Client.new(companion.private_url)
|
client = HTTP::Client.new(companion.private_url)
|
||||||
client.connect_timeout = 10.seconds
|
client.connect_timeout = 10.seconds
|
||||||
response = client.get("/healthz")
|
response = client.get(CONFIG.check_backends_path)
|
||||||
if response.status_code == 200
|
if response.status_code == 200
|
||||||
@@check_mutex.synchronize do
|
if response.content_type == "application/json"
|
||||||
updated_status[index] = Status::Working.to_i
|
body = response.body
|
||||||
updated_ends.push(index)
|
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
|
end
|
||||||
generate_csp([companion.public_url, companion.i2p_public_url], index)
|
generate_csp([companion.public_url, companion.i2p_public_url], index)
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -125,6 +125,7 @@
|
|||||||
<%= HTML.escape(CONFIG.backend_name_prefix + (index + 1).to_s) %> <%= HTML.escape(companion.note) %>
|
<%= HTML.escape(CONFIG.backend_name_prefix + (index + 1).to_s) %> <%= HTML.escape(companion.note) %>
|
||||||
<span style="color:
|
<span style="color:
|
||||||
<% if status[index] == BackendInfo::Status::Dead.to_i %> #fd4848; <% end %>
|
<% 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 %>
|
<% if status[index] == BackendInfo::Status::Working.to_i %> #42ae3c; <% end %>
|
||||||
">•</span>
|
">•</span>
|
||||||
</a>
|
</a>
|
||||||
@@ -139,6 +140,7 @@
|
|||||||
<%= HTML.escape(CONFIG.backend_name_prefix + (index + 1).to_s) %> <%= HTML.escape(companion.note) %>
|
<%= HTML.escape(CONFIG.backend_name_prefix + (index + 1).to_s) %> <%= HTML.escape(companion.note) %>
|
||||||
<span style="color:
|
<span style="color:
|
||||||
<% if status[index] == BackendInfo::Status::Dead.to_i %> #fd4848; <% end %>
|
<% 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 %>
|
<% if status[index] == BackendInfo::Status::Working.to_i %> #42ae3c; <% end %>
|
||||||
">•</span>
|
">•</span>
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
Reference in New Issue
Block a user