From b2a24bf0ae64315116cc7896fd43d1057ece6dbb Mon Sep 17 00:00:00 2001 From: syeopite Date: Fri, 25 Jun 2021 21:26:33 -0700 Subject: [PATCH] Add config opt. to view chan vid page by default --- src/invidious.cr | 3 +- src/invidious/helpers/helpers.cr | 1 + src/invidious/routes/channels.cr | 8 +++ src/invidious/routes/preferences.cr | 65 ++++++++++--------- src/invidious/users.cr | 1 + .../views/components/channel-information.ecr | 4 +- src/invidious/views/preferences.ecr | 7 ++ 7 files changed, 56 insertions(+), 33 deletions(-) diff --git a/src/invidious.cr b/src/invidious.cr index a1ed3fc7..a4cda7fd 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -309,7 +309,8 @@ Invidious::Routing.get "/", Invidious::Routes::Misc, :home Invidious::Routing.get "/privacy", Invidious::Routes::Misc, :privacy Invidious::Routing.get "/licenses", Invidious::Routes::Misc, :licenses -Invidious::Routing.get "/channel/:ucid", Invidious::Routes::Channels, :home +Invidious::Routing.get "/channel/:ucid", Invidious::Routes::Channels, :channel +Invidious::Routing.get "/channel/:ucid/home", Invidious::Routes::Channels, :home Invidious::Routing.get "/channel/:ucid/videos", Invidious::Routes::Channels, :videos Invidious::Routing.get "/channel/:ucid/playlists", Invidious::Routes::Channels, :playlists Invidious::Routing.get "/channel/:ucid/community", Invidious::Routes::Channels, :community diff --git a/src/invidious/helpers/helpers.cr b/src/invidious/helpers/helpers.cr index 05fd1284..bc99c088 100644 --- a/src/invidious/helpers/helpers.cr +++ b/src/invidious/helpers/helpers.cr @@ -55,6 +55,7 @@ struct ConfigPreferences property volume : Int32 = 100 property vr_mode : Bool = true property show_nick : Bool = true + property view_channel_homepage_by_default : Bool = true def to_tuple {% begin %} diff --git a/src/invidious/routes/channels.cr b/src/invidious/routes/channels.cr index 1380d9b3..3e897eee 100644 --- a/src/invidious/routes/channels.cr +++ b/src/invidious/routes/channels.cr @@ -1,4 +1,12 @@ class Invidious::Routes::Channels < Invidious::Routes::BaseRoute + def channel(env) + if !env.get("preferences").as(Preferences).view_channel_homepage_by_default + env.redirect "/channel/#{env.params.url["ucid"]}/videos" + else + env.redirect "/channel/#{env.params.url["ucid"]}/home" + end + end + def home(env) data = self.fetch_basic_information(env) if !data.is_a?(Tuple) diff --git a/src/invidious/routes/preferences.cr b/src/invidious/routes/preferences.cr index b2c71680..57c68b7c 100644 --- a/src/invidious/routes/preferences.cr +++ b/src/invidious/routes/preferences.cr @@ -72,6 +72,10 @@ class Invidious::Routes::PreferencesRoute < Invidious::Routes::BaseRoute show_nick ||= "off" show_nick = show_nick == "on" + view_channel_homepage_by_default = env.params.body["view_channel_homepage_by_default"]?.try &.as(String) + view_channel_homepage_by_default ||= "off" + view_channel_homepage_by_default = view_channel_homepage_by_default == "on" + comments = [] of String 2.times do |i| comments << (env.params.body["comments[#{i}]"]?.try &.as(String) || CONFIG.default_user_preferences.comments[i]) @@ -130,36 +134,37 @@ class Invidious::Routes::PreferencesRoute < Invidious::Routes::BaseRoute # Convert to JSON and back again to take advantage of converters used for compatability preferences = Preferences.from_json({ - annotations: annotations, - annotations_subscribed: annotations_subscribed, - autoplay: autoplay, - captions: captions, - comments: comments, - continue: continue, - continue_autoplay: continue_autoplay, - dark_mode: dark_mode, - latest_only: latest_only, - listen: listen, - local: local, - locale: locale, - max_results: max_results, - notifications_only: notifications_only, - player_style: player_style, - quality: quality, - quality_dash: quality_dash, - default_home: default_home, - feed_menu: feed_menu, - automatic_instance_redirect: automatic_instance_redirect, - related_videos: related_videos, - sort: sort, - speed: speed, - thin_mode: thin_mode, - unseen_only: unseen_only, - video_loop: video_loop, - volume: volume, - extend_desc: extend_desc, - vr_mode: vr_mode, - show_nick: show_nick, + annotations: annotations, + annotations_subscribed: annotations_subscribed, + autoplay: autoplay, + captions: captions, + comments: comments, + continue: continue, + continue_autoplay: continue_autoplay, + dark_mode: dark_mode, + latest_only: latest_only, + listen: listen, + local: local, + locale: locale, + max_results: max_results, + notifications_only: notifications_only, + player_style: player_style, + quality: quality, + quality_dash: quality_dash, + default_home: default_home, + feed_menu: feed_menu, + automatic_instance_redirect: automatic_instance_redirect, + related_videos: related_videos, + sort: sort, + speed: speed, + thin_mode: thin_mode, + unseen_only: unseen_only, + video_loop: video_loop, + volume: volume, + extend_desc: extend_desc, + vr_mode: vr_mode, + show_nick: show_nick, + view_channel_homepage_by_default: view_channel_homepage_by_default, }.to_json).to_json if user = env.get? "user" diff --git a/src/invidious/users.cr b/src/invidious/users.cr index aff76b53..a54c6169 100644 --- a/src/invidious/users.cr +++ b/src/invidious/users.cr @@ -56,6 +56,7 @@ struct Preferences property local : Bool = CONFIG.default_user_preferences.local property vr_mode : Bool = CONFIG.default_user_preferences.vr_mode property show_nick : Bool = CONFIG.default_user_preferences.show_nick + property view_channel_homepage_by_default : Bool = CONFIG.default_user_preferences.view_channel_homepage_by_default @[JSON::Field(converter: Preferences::ProcessString)] property locale : String = CONFIG.default_user_preferences.locale diff --git a/src/invidious/views/components/channel-information.ecr b/src/invidious/views/components/channel-information.ecr index 44663e5d..3432f7ca 100644 --- a/src/invidious/views/components/channel-information.ecr +++ b/src/invidious/views/components/channel-information.ecr @@ -69,13 +69,13 @@