mirror of
https://git.nadeko.net/Fijxu/invidious.git
synced 2025-06-28 01:48:26 +00:00
Update API to only try working backends with companion
This commit is contained in:
parent
3d3321eec0
commit
4dcd6dd2f4
@ -3,10 +3,19 @@ module BackendInfo
|
|||||||
@@exvpp_url : Array(String) = Array.new(CONFIG.invidious_companion.size, "")
|
@@exvpp_url : Array(String) = Array.new(CONFIG.invidious_companion.size, "")
|
||||||
@@status : Array(Int32) = Array.new(CONFIG.invidious_companion.size, 0)
|
@@status : Array(Int32) = Array.new(CONFIG.invidious_companion.size, 0)
|
||||||
@@csp : Array(String) = Array.new(CONFIG.invidious_companion.size, "")
|
@@csp : Array(String) = Array.new(CONFIG.invidious_companion.size, "")
|
||||||
|
@@working_ends : Array(Int32) = Array(Int32).new(0)
|
||||||
@@mutex : Mutex = Mutex.new
|
@@mutex : Mutex = Mutex.new
|
||||||
|
|
||||||
def check_backends
|
def check_backends
|
||||||
check_companion()
|
check_companion()
|
||||||
|
LOGGER.debug("Invidious companion: Updating working_ends")
|
||||||
|
@@working_ends.clear
|
||||||
|
@@status.each_with_index do |_, index|
|
||||||
|
if @@status[index] == 2
|
||||||
|
@@working_ends.push(index)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
LOGGER.debug("Invidious companion: New working_ends \"#{@@working_ends}\"")
|
||||||
end
|
end
|
||||||
|
|
||||||
private def check_companion
|
private def check_companion
|
||||||
@ -70,6 +79,10 @@ module BackendInfo
|
|||||||
return @@status
|
return @@status
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_working_ends
|
||||||
|
return @@working_ends
|
||||||
|
end
|
||||||
|
|
||||||
def get_exvpp
|
def get_exvpp
|
||||||
return @@exvpp_url
|
return @@exvpp_url
|
||||||
end
|
end
|
||||||
|
@ -46,7 +46,7 @@ module Invidious::Routes::BeforeAll
|
|||||||
begin
|
begin
|
||||||
current_companion = env.request.cookies[CONFIG.server_id_cookie_name].value.try &.to_i
|
current_companion = env.request.cookies[CONFIG.server_id_cookie_name].value.try &.to_i
|
||||||
rescue
|
rescue
|
||||||
current_companion = rand(CONFIG.invidious_companion.size)
|
current_companion = BackendInfo.get_working_ends.sample
|
||||||
end
|
end
|
||||||
|
|
||||||
if current_companion > CONFIG.invidious_companion.size
|
if current_companion > CONFIG.invidious_companion.size
|
||||||
|
@ -689,10 +689,11 @@ module YoutubeAPI
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
if env.nil?
|
if env.nil?
|
||||||
current_companion = rand(CONFIG.invidious_companion.size)
|
current_companion = BackendInfo.get_working_ends.sample
|
||||||
else
|
else
|
||||||
current_companion = env.get("current_companion").as(Int32)
|
current_companion = env.get("current_companion").as(Int32)
|
||||||
end
|
end
|
||||||
|
LOGGER.trace("Invidious companion: current_companion: #{current_companion}")
|
||||||
response = COMPANION_POOL[current_companion].client &.post(endpoint, headers: headers, body: data.to_json)
|
response = COMPANION_POOL[current_companion].client &.post(endpoint, headers: headers, body: data.to_json)
|
||||||
body = response.body
|
body = response.body
|
||||||
if (response.status_code != 200)
|
if (response.status_code != 200)
|
||||||
|
Loading…
Reference in New Issue
Block a user