mirror of
https://github.com/iv-org/invidious.git
synced 2024-12-23 22:39:31 -05:00
Allow thumbnail queries with QUIC disabled
This commit is contained in:
parent
814c9e6c3a
commit
83556bace2
@ -223,7 +223,17 @@ module Invidious::Routes::Images
|
|||||||
id = env.params.url["id"]
|
id = env.params.url["id"]
|
||||||
name = env.params.url["name"]
|
name = env.params.url["name"]
|
||||||
|
|
||||||
headers = HTTP::Headers{":authority" => "i.ytimg.com"}
|
headers = (
|
||||||
|
{% unless flag?(:disable_quic) %}
|
||||||
|
if CONFIG.use_quic
|
||||||
|
HTTP::Headers{":authority" => "i.ytimg.com"}
|
||||||
|
else
|
||||||
|
HTTP::Headers.new
|
||||||
|
end
|
||||||
|
{% else %}
|
||||||
|
HTTP::Headers.new
|
||||||
|
{% end %}
|
||||||
|
)
|
||||||
|
|
||||||
if name == "maxres.jpg"
|
if name == "maxres.jpg"
|
||||||
build_thumbnails(id).each do |thumb|
|
build_thumbnails(id).each do |thumb|
|
||||||
@ -233,6 +243,7 @@ module Invidious::Routes::Images
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
url = "/vi/#{id}/#{name}"
|
url = "/vi/#{id}/#{name}"
|
||||||
|
|
||||||
REQUEST_HEADERS_WHITELIST.each do |header|
|
REQUEST_HEADERS_WHITELIST.each do |header|
|
||||||
@ -241,25 +252,43 @@ module Invidious::Routes::Images
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
request_proc = ->(response : HTTP::Client::Response) {
|
||||||
|
env.response.status_code = response.status_code
|
||||||
|
response.headers.each do |key, value|
|
||||||
|
if !RESPONSE_HEADERS_BLACKLIST.includes?(key.downcase)
|
||||||
|
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")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
proxy_file(response, env)
|
||||||
|
}
|
||||||
|
|
||||||
begin
|
begin
|
||||||
YT_POOL.client &.get(url, headers) do |response|
|
{% unless flag?(:disable_quic) %}
|
||||||
env.response.status_code = response.status_code
|
if CONFIG.use_quic
|
||||||
response.headers.each do |key, value|
|
YT_POOL.client &.get(url, headers) do |resp|
|
||||||
if !RESPONSE_HEADERS_BLACKLIST.includes?(key.downcase)
|
return request_proc.call(resp)
|
||||||
env.response.headers[key] = value
|
end
|
||||||
|
else
|
||||||
|
HTTP::Client.get("https://i.ytimg.com#{url}") do |resp|
|
||||||
|
return request_proc.call(resp)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
{% else %}
|
||||||
env.response.headers["Access-Control-Allow-Origin"] = "*"
|
# This can likely be optimized into a (small) pool sometime in the future.
|
||||||
|
HTTP::Client.get("https://i.ytimg.com#{url}") do |resp|
|
||||||
if response.status_code >= 300 && response.status_code != 404
|
return request_proc.call(resp)
|
||||||
env.response.headers.delete("Transfer-Encoding")
|
|
||||||
break
|
|
||||||
end
|
end
|
||||||
|
{% end %}
|
||||||
proxy_file(response, env)
|
|
||||||
end
|
|
||||||
rescue ex
|
rescue ex
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user