Add separate handler for /profile endpoint

This commit is contained in:
syeopite 2021-06-29 09:11:07 -07:00
parent bf6b9a0b86
commit 6d8e8c4c79
No known key found for this signature in database
GPG Key ID: 6FA616E5A5294A82
2 changed files with 17 additions and 2 deletions

View File

@ -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

View File

@ -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]?