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, "")
|
||||
@@status : Array(Int32) = Array.new(CONFIG.invidious_companion.size, 0)
|
||||
@@csp : Array(String) = Array.new(CONFIG.invidious_companion.size, "")
|
||||
@@working_ends : Array(Int32) = Array(Int32).new(0)
|
||||
@@mutex : Mutex = Mutex.new
|
||||
|
||||
def check_backends
|
||||
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
|
||||
|
||||
private def check_companion
|
||||
@ -70,6 +79,10 @@ module BackendInfo
|
||||
return @@status
|
||||
end
|
||||
|
||||
def get_working_ends
|
||||
return @@working_ends
|
||||
end
|
||||
|
||||
def get_exvpp
|
||||
return @@exvpp_url
|
||||
end
|
||||
|
@ -46,7 +46,7 @@ module Invidious::Routes::BeforeAll
|
||||
begin
|
||||
current_companion = env.request.cookies[CONFIG.server_id_cookie_name].value.try &.to_i
|
||||
rescue
|
||||
current_companion = rand(CONFIG.invidious_companion.size)
|
||||
current_companion = BackendInfo.get_working_ends.sample
|
||||
end
|
||||
|
||||
if current_companion > CONFIG.invidious_companion.size
|
||||
|
@ -689,10 +689,11 @@ module YoutubeAPI
|
||||
|
||||
begin
|
||||
if env.nil?
|
||||
current_companion = rand(CONFIG.invidious_companion.size)
|
||||
current_companion = BackendInfo.get_working_ends.sample
|
||||
else
|
||||
current_companion = env.get("current_companion").as(Int32)
|
||||
end
|
||||
LOGGER.trace("Invidious companion: current_companion: #{current_companion}")
|
||||
response = COMPANION_POOL[current_companion].client &.post(endpoint, headers: headers, body: data.to_json)
|
||||
body = response.body
|
||||
if (response.status_code != 200)
|
||||
|
Loading…
Reference in New Issue
Block a user