From 02e1cdf2104383f65e1f313ded326843aee77efe Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Fri, 1 Nov 2019 12:02:38 -0400 Subject: [PATCH] Add support for '/yts/img' endpoint --- src/invidious.cr | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/invidious.cr b/src/invidious.cr index aad08e40..d2d20284 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -5738,6 +5738,36 @@ get "/s_p/:id/:name" do |env| 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| id = env.params.url["id"] name = env.params.url["name"]