feat: Adds support for custom channel handle urls with tab paths (ex: {INSTANCE}/markrober/streams) (#5811)

* feat: add support for additional channel urls (:user/:tab)

* fix: check known_tabs against downcased selected_tab

* rebase, remove whitespace and move route to the correct place

---------

Co-authored-by: Fijxu <fijxu@nadeko.net>
This commit is contained in:
Cameron Radmore
2026-11-02 23:58:44 -05:00
committed by GitHub
parent 33ee40b549
commit 3df861696c
2 changed files with 15 additions and 1 deletions

View File

@@ -359,6 +359,17 @@ module Invidious::Routes::Channels
"posts", "posts",
} }
def self.potential_brand_redirect(env)
# Check for known tab in url before trying to brand_redirect (avoids unneeded request to YouTube)
selected_tab = env.params.url["tab"]?.try &.downcase
if KNOWN_TABS.includes? selected_tab
brand_redirect(env)
else
Invidious::Routes::Misc.home(env)
end
end
# Redirects brand url channels to a normal /channel/:ucid route # Redirects brand url channels to a normal /channel/:ucid route
def self.brand_redirect(env) def self.brand_redirect(env)
locale = env.get("preferences").as(Preferences).locale locale = env.get("preferences").as(Preferences).locale
@@ -381,7 +392,7 @@ module Invidious::Routes::Channels
return Errors.error_template(404, I18n.translate(locale, "This channel does not exist.")) return Errors.error_template(404, I18n.translate(locale, "This channel does not exist."))
end end
selected_tab = env.params.url["tab"]? selected_tab = env.params.url["tab"]?.try &.downcase
if KNOWN_TABS.includes? selected_tab if KNOWN_TABS.includes? selected_tab
url = "/channel/#{ucid}/#{selected_tab}" url = "/channel/#{ucid}/#{selected_tab}"

View File

@@ -146,6 +146,9 @@ module Invidious::Routing
get "/user/:user", Routes::Channels, :brand_redirect get "/user/:user", Routes::Channels, :brand_redirect
get "/user/:user/:tab", Routes::Channels, :brand_redirect get "/user/:user/:tab", Routes::Channels, :brand_redirect
# /linuxtechtips/streams
get "/:user/:tab", Routes::Channels, :potential_brand_redirect
# /@LinusTechTips (Handle) # /@LinusTechTips (Handle)
get "/@:user", Routes::Channels, :brand_redirect get "/@:user", Routes::Channels, :brand_redirect
get "/@:user/:tab", Routes::Channels, :brand_redirect get "/@:user/:tab", Routes::Channels, :brand_redirect