Manually extract brand_redirect from 1b569bbc99207cae7c20aa285f42477ae361dd30

This commit manually extracts the brand_redirect function from the
commit mentioned.

However, the redirect to the  `.../about` endpoint is removed due to the
fact that it doesn't exist yet.

This commit is also mainly just a bridge for the next few cherry picks from
\#2215
This commit is contained in:
syeopite 2021-06-28 22:15:29 -07:00
parent 389d1c5232
commit c93a0d9aa2
No known key found for this signature in database
GPG Key ID: 6FA616E5A5294A82
2 changed files with 32 additions and 0 deletions

View File

@ -315,6 +315,10 @@ Invidious::Routing.get "/channel/:ucid/playlists", Invidious::Routes::Channels,
Invidious::Routing.get "/channel/:ucid/community", Invidious::Routes::Channels, :community
Invidious::Routing.get "/channel/:ucid/about", Invidious::Routes::Channels, :about
["", "/videos", "/playlists", "/community", "/about"].each do |path|
Invidious::Routing.get "/c/:user#{path}", Invidious::Routes::Channels, :brand_redirect
end
Invidious::Routing.get "/watch", Invidious::Routes::Watch, :handle
Invidious::Routing.get "/watch/:id", Invidious::Routes::Watch, :redirect
Invidious::Routing.get "/shorts/:id", Invidious::Routes::Watch, :redirect

View File

@ -101,6 +101,34 @@ class Invidious::Routes::Channels < Invidious::Routes::BaseRoute
env.redirect "/channel/#{ucid}"
end
def brand_redirect(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]?
user = env.params.url["user"]
response = YT_POOL.client &.get("/c/#{user}")
html = XML.parse_html(response.body)
ucid = html.xpath_node(%q(//link[@rel="canonical"])).try &.["href"].split("/")[-1]
if !ucid
env.response.status_code = 404
return
end
url = "/channel/#{ucid}"
location = env.request.path.lchop?("/c/#{user}/")
if location
url += "/#{location}"
end
if env.params.query.size > 0
url += "?#{env.params.query}"
end
env.redirect url
end
private def fetch_basic_information(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]?