fix: fix wrong invidious companion logic on backends
do not change to another companion if request fails
This commit is contained in:
parent
5f1944925b
commit
fd8c40e0da
3 changed files with 16 additions and 14 deletions
|
@ -113,9 +113,11 @@ YT_POOL = YoutubeConnectionPool.new(YT_URL, capacity: CONFIG.pool_size)
|
|||
|
||||
GGPHT_POOL = YoutubeConnectionPool.new(URI.parse("https://yt3.ggpht.com"), capacity: CONFIG.pool_size)
|
||||
|
||||
COMPANION_POOL = CompanionConnectionPool.new(
|
||||
capacity: CONFIG.pool_size
|
||||
)
|
||||
COMPANION_POOL = [] of CompanionConnectionPool
|
||||
|
||||
CONFIG.invidious_companion.each do |companion|
|
||||
COMPANION_POOL << CompanionConnectionPool.new(companion, capacity: CONFIG.pool_size)
|
||||
end
|
||||
|
||||
# CLI
|
||||
Kemal.config.extra_options do |parser|
|
||||
|
|
|
@ -49,7 +49,7 @@ end
|
|||
struct CompanionConnectionPool
|
||||
property pool : DB::Pool(HTTP::Client)
|
||||
|
||||
def initialize(capacity = 5, timeout = 5.0)
|
||||
def initialize(companion, capacity = 5, timeout = 5.0)
|
||||
options = DB::Pool::Options.new(
|
||||
initial_pool_size: 0,
|
||||
max_pool_size: capacity,
|
||||
|
@ -58,12 +58,11 @@ struct CompanionConnectionPool
|
|||
)
|
||||
|
||||
@pool = DB::Pool(HTTP::Client).new(options) do
|
||||
companion = CONFIG.invidious_companion.sample
|
||||
next make_client(companion.private_url, use_http_proxy: false)
|
||||
end
|
||||
end
|
||||
|
||||
def client(env : HTTP::Server::Context | Nil, &)
|
||||
def client(&)
|
||||
conn = pool.checkout
|
||||
|
||||
begin
|
||||
|
@ -71,14 +70,10 @@ struct CompanionConnectionPool
|
|||
rescue ex
|
||||
conn.close
|
||||
|
||||
if env.nil?
|
||||
companion = CONFIG.invidious_companion.sample
|
||||
else
|
||||
current_companion = env.get("current_companion").as(Int32)
|
||||
companion = CONFIG.invidious_companion[current_companion]
|
||||
end
|
||||
scheme = "https" if conn.tls || "http"
|
||||
same_companion = "#{scheme}://#{conn.host}:#{conn.port}"
|
||||
|
||||
conn = make_client(companion.private_url, use_http_proxy: false)
|
||||
conn = make_client(URI.parse(same_companion), use_http_proxy: false)
|
||||
|
||||
response = yield conn
|
||||
ensure
|
||||
|
|
|
@ -688,7 +688,12 @@ module YoutubeAPI
|
|||
# Send the POST request
|
||||
|
||||
begin
|
||||
response = COMPANION_POOL.client(env, &.post(endpoint, headers: headers, body: data.to_json))
|
||||
if env.nil?
|
||||
current_companion = rand(CONFIG.invidious_companion.size)
|
||||
else
|
||||
current_companion = env.get("current_companion").as(Int32)
|
||||
end
|
||||
response = COMPANION_POOL[current_companion].client &.post(endpoint, headers: headers, body: data.to_json)
|
||||
body = response.body
|
||||
if (response.status_code != 200)
|
||||
raise Exception.new(
|
||||
|
|
Loading…
Add table
Reference in a new issue