Update channel routing logic to use a module

This commit is contained in:
syeopite 2021-08-09 22:54:12 -07:00
parent e8ab18f0e8
commit f735e87756
No known key found for this signature in database
GPG Key ID: 6FA616E5A5294A82

View File

@ -1,9 +1,9 @@
class Invidious::Routes::Channels < Invidious::Routes::BaseRoute module Invidious::Routes::Channels
def home(env) def self.home(env)
self.videos(env) self.videos(env)
end end
def videos(env) def self.videos(env)
data = self.fetch_basic_information(env) data = self.fetch_basic_information(env)
if !data.is_a?(Tuple) if !data.is_a?(Tuple)
return data return data
@ -40,7 +40,7 @@ class Invidious::Routes::Channels < Invidious::Routes::BaseRoute
templated "channel" templated "channel"
end end
def playlists(env) def self.playlists(env)
data = self.fetch_basic_information(env) data = self.fetch_basic_information(env)
if !data.is_a?(Tuple) if !data.is_a?(Tuple)
return data return data
@ -62,7 +62,7 @@ class Invidious::Routes::Channels < Invidious::Routes::BaseRoute
templated "playlists" templated "playlists"
end end
def community(env) def self.community(env)
data = self.fetch_basic_information(env) data = self.fetch_basic_information(env)
if !data.is_a?(Tuple) if !data.is_a?(Tuple)
return data return data
@ -91,7 +91,7 @@ class Invidious::Routes::Channels < Invidious::Routes::BaseRoute
templated "community" templated "community"
end end
def about(env) def self.about(env)
data = self.fetch_basic_information(env) data = self.fetch_basic_information(env)
if !data.is_a?(Tuple) if !data.is_a?(Tuple)
return data return data
@ -102,7 +102,7 @@ class Invidious::Routes::Channels < Invidious::Routes::BaseRoute
end end
# Redirects brand url channels to a normal /channel/:ucid route # Redirects brand url channels to a normal /channel/:ucid route
def brand_redirect(env) def self.brand_redirect(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = LOCALES[env.get("preferences").as(Preferences).locale]?
# /attribution_link endpoint needs both the `a` and `u` parameter # /attribution_link endpoint needs both the `a` and `u` parameter
@ -131,7 +131,7 @@ class Invidious::Routes::Channels < Invidious::Routes::BaseRoute
end end
# Handles redirects for the /profile endpoint # Handles redirects for the /profile endpoint
def profile(env) def self.profile(env)
# The /profile endpoint is special. If passed into the resolve_url # The /profile endpoint is special. If passed into the resolve_url
# endpoint YouTube would return a sign in page instead of an /channel/:ucid # endpoint YouTube would return a sign in page instead of an /channel/:ucid
# thus we'll add an edge case and handle it here. # thus we'll add an edge case and handle it here.
@ -146,7 +146,7 @@ class Invidious::Routes::Channels < Invidious::Routes::BaseRoute
end end
end end
private def fetch_basic_information(env) private def self.fetch_basic_information(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = LOCALES[env.get("preferences").as(Preferences).locale]?
user = env.get? "user" user = env.get? "user"