diff --git a/src/invidious.cr b/src/invidious.cr index 0a84139a..5fb6b902 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -319,7 +319,7 @@ Invidious::Routing.get "/channel/:ucid/about", Invidious::Routes::Channels, :abo Invidious::Routing.get "/c/:user#{path}", Invidious::Routes::Channels, :brand_redirect Invidious::Routing.get "/user/:user#{path}", Invidious::Routes::Channels, :brand_redirect Invidious::Routing.get "/attribution_link#{path}", Invidious::Routes::Channels, :brand_redirect - Invidious::Routing.get "/profile/:user#{path}", Invidious::Routes::Channels, :brand_redirect + Invidious::Routing.get "/profile/#{path}", Invidious::Routes::Channels, :profile end Invidious::Routing.get "/watch", Invidious::Routes::Watch, :handle diff --git a/src/invidious/routes/channels.cr b/src/invidious/routes/channels.cr index 5104f477..4e8db368 100644 --- a/src/invidious/routes/channels.cr +++ b/src/invidious/routes/channels.cr @@ -105,7 +105,6 @@ class Invidious::Routes::Channels < Invidious::Routes::BaseRoute def brand_redirect(env) locale = LOCALES[env.get("preferences").as(Preferences).locale]? - # /profile endpoint uses the `user` parameter # /attribution_link endpoint needs both the `a` and `u` parameter # and in order to avoid detection from YouTube we should only send the required ones # without any of the additional url parameters that only Invidious uses. @@ -132,6 +131,22 @@ class Invidious::Routes::Channels < Invidious::Routes::BaseRoute env.redirect url end + # Handles redirects for the /profile endpoint + def profile(env) + # The /profile endpoint is special. If passed into the resolve_url + # endpoint YouTube would return a sign in page instead of an /channel/:ucid + # thus we'll add an edge case and handle it here. + + uri_params = env.params.query.size > 0 ? "?#{env.params.query}" : "" + + user = env.params.query["user"]? + if !user + raise InfoException.new("This channel does not exist.") + else + env.redirect "/user/#{user}#{uri_params}" + end + end + private def fetch_basic_information(env) locale = LOCALES[env.get("preferences").as(Preferences).locale]?