improve readability

This commit is contained in:
Theo Fischer 2025-08-17 12:01:32 +02:00
parent 08a53df7f4
commit 4d1f10a30d

View File

@ -4,8 +4,10 @@ module Invidious::Routes::ErrorRoutes
if HOST_URL.empty? && env.request.path.starts_with?("/v1/storyboards/sb") if HOST_URL.empty? && env.request.path.starts_with?("/v1/storyboards/sb")
return env.redirect "#{env.request.path[15..]}?#{env.params.query}" return env.redirect "#{env.request.path[15..]}?#{env.params.query}"
end end
if md = env.request.path.match(/^\/(?<id>([a-zA-Z0-9_-]{11})|(\w+))$/) if md = env.request.path.match(/^\/(?<id>([a-zA-Z0-9_-]{11})|(\w+))$/)
item = md["id"] item = md["id"]
# Check if item is branding URL e.g. https://youtube.com/gaming # Check if item is branding URL e.g. https://youtube.com/gaming
headers = HTTP::Headers{ headers = HTTP::Headers{
"Cookie" => "SOCS=CAE" # Cookies to prevent redirects to Cookie Consent Page CAE~Reject all, CAA~showing the cookie banner, CAI~Accept all "Cookie" => "SOCS=CAE" # Cookies to prevent redirects to Cookie Consent Page CAE~Reject all, CAA~showing the cookie banner, CAI~Accept all
@ -33,10 +35,12 @@ module Invidious::Routes::ErrorRoutes
params << "#{k}=#{v}" params << "#{k}=#{v}"
end end
params = params.join("&") params = params.join("&")
url = "/watch?v=#{item}" url = "/watch?v=#{item}"
if !params.empty? if !params.empty?
url += "&#{params}" url += "&#{params}"
end end
# Check if item is video ID # Check if item is video ID
if item.match(/^[a-zA-Z0-9_-]{11}$/) && YT_POOL.client &.head("/watch?v=#{item}").status_code != 404 if item.match(/^[a-zA-Z0-9_-]{11}$/) && YT_POOL.client &.head("/watch?v=#{item}").status_code != 404
env.response.headers["Location"] = url env.response.headers["Location"] = url