mirror of
https://github.com/iv-org/invidious.git
synced 2025-08-14 08:38:30 +00:00
Manually extract brand_redirect from 1b569bbc99
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:
parent
389d1c5232
commit
c93a0d9aa2
@ -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/community", Invidious::Routes::Channels, :community
|
||||||
Invidious::Routing.get "/channel/:ucid/about", Invidious::Routes::Channels, :about
|
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", Invidious::Routes::Watch, :handle
|
||||||
Invidious::Routing.get "/watch/:id", Invidious::Routes::Watch, :redirect
|
Invidious::Routing.get "/watch/:id", Invidious::Routes::Watch, :redirect
|
||||||
Invidious::Routing.get "/shorts/:id", Invidious::Routes::Watch, :redirect
|
Invidious::Routing.get "/shorts/:id", Invidious::Routes::Watch, :redirect
|
||||||
|
@ -101,6 +101,34 @@ class Invidious::Routes::Channels < Invidious::Routes::BaseRoute
|
|||||||
env.redirect "/channel/#{ucid}"
|
env.redirect "/channel/#{ucid}"
|
||||||
end
|
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)
|
private def fetch_basic_information(env)
|
||||||
locale = LOCALES[env.get("preferences").as(Preferences).locale]?
|
locale = LOCALES[env.get("preferences").as(Preferences).locale]?
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user