Add support for '/yts/img' endpoint

This commit is contained in:
Omar Roth 2019-11-01 12:02:38 -04:00
parent b58950c574
commit 02e1cdf210
No known key found for this signature in database
GPG Key ID: B8254FB7EC3D37F2
1 changed files with 30 additions and 0 deletions

View File

@ -5738,6 +5738,36 @@ get "/s_p/:id/:name" do |env|
end end
end end
get "/yts/img/:name" do |env|
headers = HTTP::Headers.new
REQUEST_HEADERS_WHITELIST.each do |header|
if env.request.headers[header]?
headers[header] = env.request.headers[header]
end
end
begin
YT_POOL.client &.get(env.request.resource, headers) do |response|
env.response.status_code = response.status_code
response.headers.each do |key, value|
if !RESPONSE_HEADERS_BLACKLIST.includes? key
env.response.headers[key] = value
end
end
env.response.headers["Access-Control-Allow-Origin"] = "*"
if response.status_code >= 300 && response.status_code != 404
env.response.headers.delete("Transfer-Encoding")
break
end
proxy_file(response, env)
end
rescue ex
end
end
get "/vi/:id/:name" do |env| get "/vi/:id/:name" do |env|
id = env.params.url["id"] id = env.params.url["id"]
name = env.params.url["name"] name = env.params.url["name"]