This commit is contained in:
Fijxu 2026-07-23 15:35:03 -04:00
parent c6dfc0017d
commit 1dceabf4f2
No known key found for this signature in database
GPG Key ID: 32C1DDF333EDA6A4

View File

@ -1,20 +1,22 @@
module Invidious::Routes::Companion module Invidious::Routes::Companion
extend self
# GET /companion # GET /companion
def self.get_companion(env) def get_companion(env)
url = self.make_url url = make_url(env)
self.proxy_companion(env, "GET", url) proxy_companion(env, "GET", url)
end end
# POST /companion # POST /companion
def self.post_companion(env) def post_companion(env)
url = self.make_url url = make_url(env)
self.proxy_companion(env, "POST", url) proxy_companion(env, "POST", url)
end end
# OPTIONS /companion # OPTIONS /companion
def self.options_companion(env) def options_companion(env)
url = self.make_url url = make_url(env)
self.proxy_companion(env, "OPTIONS", url) proxy_companion(env, "OPTIONS", url)
end end
private def make_url(env) private def make_url(env)
@ -22,9 +24,10 @@ module Invidious::Routes::Companion
if env.request.query if env.request.query
url += "?#{env.request.query}" url += "?#{env.request.query}"
end end
url
end end
private def self.proxy_companion(env, method, url) private def proxy_companion(env, method, url)
begin begin
COMPANION_POOL.client do |wrapper| COMPANION_POOL.client do |wrapper|
wrapper.client.exec(method, url, env.request.headers, (env.request.body if method == "POST")) do |resp| wrapper.client.exec(method, url, env.request.headers, (env.request.body if method == "POST")) do |resp|