Move feed_menu and default_home into user preferences

This commit is contained in:
Omar Roth 2019-10-20 20:42:18 -04:00
parent 2a04a48b89
commit 7524b5e349
No known key found for this signature in database
GPG key ID: B8254FB7EC3D37F2
11 changed files with 97 additions and 53 deletions

View file

@ -115,9 +115,9 @@
"Feed menu: ": "Feed menu: ", "Feed menu: ": "Feed menu: ",
"Top enabled: ": "Top enabled: ", "Top enabled: ": "Top enabled: ",
"CAPTCHA enabled: ": "CAPTCHA enabled: ", "CAPTCHA enabled: ": "CAPTCHA enabled: ",
"Login enabled: ": "Login enabled? ", "Login enabled: ": "Login enabled: ",
"Registration enabled: ": "Registration enabled? ", "Registration enabled: ": "Registration enabled: ",
"Report statistics: ": "Report statistics? ", "Report statistics: ": "Report statistics: ",
"Save preferences": "Save preferences", "Save preferences": "Save preferences",
"Subscription manager": "Subscription manager", "Subscription manager": "Subscription manager",
"Token manager": "Token manager", "Token manager": "Token manager",

View file

@ -293,10 +293,8 @@ before_all do |env|
end end
dark_mode = convert_theme(env.params.query["dark_mode"]?) || preferences.dark_mode.to_s dark_mode = convert_theme(env.params.query["dark_mode"]?) || preferences.dark_mode.to_s
thin_mode = env.params.query["thin_mode"]? || preferences.thin_mode.to_s thin_mode = env.params.query["thin_mode"]? || preferences.thin_mode.to_s
thin_mode = thin_mode == "true" thin_mode = thin_mode == "true"
locale = env.params.query["hl"]? || preferences.locale locale = env.params.query["hl"]? || preferences.locale
preferences.dark_mode = dark_mode preferences.dark_mode = dark_mode
@ -319,21 +317,21 @@ before_all do |env|
end end
get "/" do |env| get "/" do |env|
locale = LOCALES[env.get("preferences").as(Preferences).locale]? preferences = env.get("preferences").as(Preferences)
locale = LOCALES[preferences.locale]?
user = env.get? "user" user = env.get? "user"
if user case preferences.default_home
user = user.as(User) when ""
if user.preferences.redirect_feed templated "empty"
next env.redirect "/feed/subscriptions"
end
end
case config.default_home
when "Popular" when "Popular"
templated "popular" templated "popular"
when "Top" when "Top"
templated "top" if config.top_enabled
templated "top"
else
templated "empty"
end
when "Trending" when "Trending"
env.redirect "/feed/trending" env.redirect "/feed/trending"
when "Subscriptions" when "Subscriptions"
@ -342,6 +340,12 @@ get "/" do |env|
else else
templated "popular" templated "popular"
end end
when "Playlists"
if user
env.redirect "/view_all_playlists"
else
templated "popular"
end
end end
end end
@ -783,6 +787,10 @@ end
# Playlists # Playlists
get "/feed/playlists" do |env|
env.redirect "/view_all_playlists"
end
get "/view_all_playlists" do |env| get "/view_all_playlists" do |env|
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = LOCALES[env.get("preferences").as(Preferences).locale]?
@ -1952,9 +1960,15 @@ post "/preferences" do |env|
related_videos ||= "off" related_videos ||= "off"
related_videos = related_videos == "on" related_videos = related_videos == "on"
redirect_feed = env.params.body["redirect_feed"]?.try &.as(String) default_home = env.params.body["default_home"]?.try &.as(String) || CONFIG.default_user_preferences.default_home
redirect_feed ||= "off"
redirect_feed = redirect_feed == "on" feed_menu = [] of String
5.times do |index|
option = env.params.body["feed_menu[#{index}]"]?.try &.as(String) || ""
if !option.empty?
feed_menu << option
end
end
locale = env.params.body["locale"]?.try &.as(String) locale = env.params.body["locale"]?.try &.as(String)
locale ||= CONFIG.default_user_preferences.locale locale ||= CONFIG.default_user_preferences.locale
@ -2002,7 +2016,8 @@ post "/preferences" do |env|
notifications_only: notifications_only, notifications_only: notifications_only,
player_style: player_style, player_style: player_style,
quality: quality, quality: quality,
redirect_feed: redirect_feed, default_home: default_home,
feed_menu: feed_menu,
related_videos: related_videos, related_videos: related_videos,
sort: sort, sort: sort,
speed: speed, speed: speed,
@ -2017,16 +2032,16 @@ post "/preferences" do |env|
PG_DB.exec("UPDATE users SET preferences = $1 WHERE email = $2", preferences, user.email) PG_DB.exec("UPDATE users SET preferences = $1 WHERE email = $2", preferences, user.email)
if config.admins.includes? user.email if config.admins.includes? user.email
config.default_home = env.params.body["default_home"]?.try &.as(String) || config.default_home CONFIG.default_user_preferences.default_home = env.params.body["admin_default_home"]?.try &.as(String) || CONFIG.default_user_preferences.default_home
feed_menu = [] of String admin_feed_menu = [] of String
4.times do |index| 5.times do |index|
option = env.params.body["feed_menu[#{index}]"]?.try &.as(String) || "" option = env.params.body["admin_feed_menu[#{index}]"]?.try &.as(String) || ""
if !option.empty? if !option.empty?
feed_menu << option admin_feed_menu << option
end end
end end
config.feed_menu = feed_menu CONFIG.default_user_preferences.feed_menu = admin_feed_menu
top_enabled = env.params.body["top_enabled"]?.try &.as(String) top_enabled = env.params.body["top_enabled"]?.try &.as(String)
top_enabled ||= "off" top_enabled ||= "off"

View file

@ -94,9 +94,7 @@ struct ConfigPreferences
result result
end end
rescue ex rescue ex
result = value.read_bool if value.read_bool
if result
"dark" "dark"
else else
"light" "light"
@ -110,7 +108,7 @@ struct ConfigPreferences
def self.from_yaml(ctx : YAML::ParseContext, node : YAML::Nodes::Node) : String def self.from_yaml(ctx : YAML::ParseContext, node : YAML::Nodes::Node) : String
unless node.is_a?(YAML::Nodes::Scalar) unless node.is_a?(YAML::Nodes::Scalar)
node.raise "Expected sequence, not #{node.class}" node.raise "Expected scalar, not #{node.class}"
end end
case node.value case node.value
@ -134,7 +132,7 @@ struct ConfigPreferences
comments: {type: Array(String), default: ["youtube", ""], converter: StringToArray}, comments: {type: Array(String), default: ["youtube", ""], converter: StringToArray},
continue: {type: Bool, default: false}, continue: {type: Bool, default: false},
continue_autoplay: {type: Bool, default: true}, continue_autoplay: {type: Bool, default: true},
dark_mode: {type: String, default: "", converter: BoolToString}, dark_mode: {type: String, default: "light", converter: BoolToString},
latest_only: {type: Bool, default: false}, latest_only: {type: Bool, default: false},
listen: {type: Bool, default: false}, listen: {type: Bool, default: false},
local: {type: Bool, default: false}, local: {type: Bool, default: false},
@ -143,7 +141,8 @@ struct ConfigPreferences
notifications_only: {type: Bool, default: false}, notifications_only: {type: Bool, default: false},
player_style: {type: String, default: "invidious"}, player_style: {type: String, default: "invidious"},
quality: {type: String, default: "hd720"}, quality: {type: String, default: "hd720"},
redirect_feed: {type: Bool, default: false}, default_home: {type: String, default: "Popular"},
feed_menu: {type: Array(String), default: ["Popular", "Trending", "Subscriptions", "Playlists"]},
related_videos: {type: Bool, default: true}, related_videos: {type: Bool, default: true},
sort: {type: String, default: "published"}, sort: {type: String, default: "published"},
speed: {type: Float32, default: 1.0_f32}, speed: {type: Float32, default: 1.0_f32},
@ -215,8 +214,6 @@ struct Config
hmac_key: String?, # HMAC signing key for CSRF tokens and verifying pubsub subscriptions hmac_key: String?, # HMAC signing key for CSRF tokens and verifying pubsub subscriptions
domain: String?, # Domain to be used for links to resources on the site where an absolute URL is required domain: String?, # Domain to be used for links to resources on the site where an absolute URL is required
use_pubsub_feeds: {type: Bool | Int32, default: false}, # Subscribe to channels using PubSubHubbub (requires domain, hmac_key) use_pubsub_feeds: {type: Bool | Int32, default: false}, # Subscribe to channels using PubSubHubbub (requires domain, hmac_key)
default_home: {type: String, default: "Top"},
feed_menu: {type: Array(String), default: ["Popular", "Top", "Trending", "Subscriptions"]},
top_enabled: {type: Bool, default: true}, top_enabled: {type: Bool, default: true},
captcha_enabled: {type: Bool, default: true}, captcha_enabled: {type: Bool, default: true},
login_enabled: {type: Bool, default: true}, login_enabled: {type: Bool, default: true},

View file

@ -84,7 +84,8 @@ struct Preferences
notifications_only: {type: Bool, default: CONFIG.default_user_preferences.notifications_only}, notifications_only: {type: Bool, default: CONFIG.default_user_preferences.notifications_only},
player_style: {type: String, default: CONFIG.default_user_preferences.player_style, converter: ProcessString}, player_style: {type: String, default: CONFIG.default_user_preferences.player_style, converter: ProcessString},
quality: {type: String, default: CONFIG.default_user_preferences.quality, converter: ProcessString}, quality: {type: String, default: CONFIG.default_user_preferences.quality, converter: ProcessString},
redirect_feed: {type: Bool, default: CONFIG.default_user_preferences.redirect_feed}, default_home: {type: String, default: CONFIG.default_user_preferences.default_home},
feed_menu: {type: Array(String), default: CONFIG.default_user_preferences.feed_menu},
related_videos: {type: Bool, default: CONFIG.default_user_preferences.related_videos}, related_videos: {type: Bool, default: CONFIG.default_user_preferences.related_videos},
sort: {type: String, default: CONFIG.default_user_preferences.sort, converter: ProcessString}, sort: {type: String, default: CONFIG.default_user_preferences.sort, converter: ProcessString},
speed: {type: Float32, default: CONFIG.default_user_preferences.speed}, speed: {type: Float32, default: CONFIG.default_user_preferences.speed},

View file

@ -2,9 +2,9 @@
<div class="pure-u-1 pure-u-md-1-4"></div> <div class="pure-u-1 pure-u-md-1-4"></div>
<div class="pure-u-1 pure-u-md-1-2"> <div class="pure-u-1 pure-u-md-1-2">
<div class="pure-g"> <div class="pure-g">
<% feed_menu = config.feed_menu.dup %> <% feed_menu = env.get("preferences").as(Preferences).feed_menu.dup %>
<% if !env.get?("user") %> <% if !env.get?("user") %>
<% feed_menu.reject! {|feed| feed == "Subscriptions"} %> <% feed_menu.reject! {|item| {"Subscriptions", "Playlists"}.includes? item} %>
<% end %> <% end %>
<% feed_menu.each do |feed| %> <% feed_menu.each do |feed| %>
<div class="pure-u-1-2 pure-u-md-1-<%= feed_menu.size %>"> <div class="pure-u-1-2 pure-u-md-1-<%= feed_menu.size %>">

View file

@ -0,0 +1,8 @@
<% content_for "header" do %>
<meta name="description" content="<%= translate(locale, "An alternative front-end to YouTube") %>">
<title>
Invidious
</title>
<% end %>
<%= rendered "components/feed_menu" %>

View file

@ -1,7 +1,7 @@
<% content_for "header" do %> <% content_for "header" do %>
<meta name="description" content="<%= translate(locale, "An alternative front-end to YouTube") %>"> <meta name="description" content="<%= translate(locale, "An alternative front-end to YouTube") %>">
<title> <title>
<% if config.default_home != "Popular" %> <% if env.get("preferences").as(Preferences).default_home != "Popular" %>
<%= translate(locale, "Popular") %> - Invidious <%= translate(locale, "Popular") %> - Invidious
<% else %> <% else %>
Invidious Invidious

View file

@ -135,6 +135,32 @@ function update_value(element) {
<input name="thin_mode" id="thin_mode" type="checkbox" <% if preferences.thin_mode %>checked<% end %>> <input name="thin_mode" id="thin_mode" type="checkbox" <% if preferences.thin_mode %>checked<% end %>>
</div> </div>
<% if env.get?("user") %>
<% feed_options = {"", "Popular", "Top", "Trending", "Subscriptions", "Playlists"} %>
<% else %>
<% feed_options = {"", "Popular", "Top", "Trending"} %>
<% end %>
<div class="pure-control-group">
<label for="default_home"><%= translate(locale, "Default homepage: ") %></label>
<select name="default_home" id="default_home">
<% feed_options.each do |option| %>
<option value="<%= option %>" <% if preferences.default_home == option %> selected <% end %>><%= translate(locale, option) %></option>
<% end %>
</select>
</div>
<div class="pure-control-group">
<label for="feed_menu"><%= translate(locale, "Feed menu: ") %></label>
<% (feed_options.size - 1).times do |index| %>
<select name="feed_menu[<%= index %>]" id="feed_menu[<%= index %>]">
<% feed_options.each do |option| %>
<option value="<%= option %>" <% if preferences.feed_menu[index]? == option %> selected <% end %>><%= translate(locale, option) %></option>
<% end %>
</select>
<% end %>
</div>
<% if env.get? "user" %> <% if env.get? "user" %>
<legend><%= translate(locale, "Subscription preferences") %></legend> <legend><%= translate(locale, "Subscription preferences") %></legend>
@ -143,11 +169,6 @@ function update_value(element) {
<input name="annotations_subscribed" id="annotations_subscribed" type="checkbox" <% if preferences.annotations_subscribed %>checked<% end %>> <input name="annotations_subscribed" id="annotations_subscribed" type="checkbox" <% if preferences.annotations_subscribed %>checked<% end %>>
</div> </div>
<div class="pure-control-group">
<label for="redirect_feed"><%= translate(locale, "Redirect homepage to feed: ") %></label>
<input name="redirect_feed" id="redirect_feed" type="checkbox" <% if preferences.redirect_feed %>checked<% end %>>
</div>
<div class="pure-control-group"> <div class="pure-control-group">
<label for="max_results"><%= translate(locale, "Number of videos shown in feed: ") %></label> <label for="max_results"><%= translate(locale, "Number of videos shown in feed: ") %></label>
<input name="max_results" id="max_results" type="number" value="<%= preferences.max_results %>"> <input name="max_results" id="max_results" type="number" value="<%= preferences.max_results %>">
@ -193,20 +214,20 @@ function update_value(element) {
<legend><%= translate(locale, "Administrator preferences") %></legend> <legend><%= translate(locale, "Administrator preferences") %></legend>
<div class="pure-control-group"> <div class="pure-control-group">
<label for="default_home"><%= translate(locale, "Default homepage: ") %></label> <label for="admin_default_home"><%= translate(locale, "Default homepage: ") %></label>
<select name="default_home" id="default_home"> <select name="admin_default_home" id="admin_default_home">
<% {"Popular", "Top", "Trending", "Subscriptions"}.each do |option| %> <% feed_options.each do |option| %>
<option value="<%= option %>" <% if config.default_home == option %> selected <% end %>><%= translate(locale, option) %></option> <option value="<%= option %>" <% if CONFIG.default_user_preferences.default_home == option %> selected <% end %>><%= translate(locale, option) %></option>
<% end %> <% end %>
</select> </select>
</div> </div>
<div class="pure-control-group"> <div class="pure-control-group">
<label for="feed_menu"><%= translate(locale, "Feed menu: ") %></label> <label for="admin_feed_menu"><%= translate(locale, "Feed menu: ") %></label>
<% 4.times do |index| %> <% (feed_options.size - 1).times do |index| %>
<select name="feed_menu[<%= index %>]" id="feed_menu[<%= index %>]"> <select name="admin_feed_menu[<%= index %>]" id="admin_feed_menu[<%= index %>]">
<% {"", "Popular", "Top", "Trending", "Subscriptions"}.each do |option| %> <% feed_options.each do |option| %>
<option value="<%= option %>" <% if config.feed_menu[index]? == option %> selected <% end %>><%= translate(locale, option) %></option> <option value="<%= option %>" <% if CONFIG.default_user_preferences.feed_menu[index]? == option %> selected <% end %>><%= translate(locale, option) %></option>
<% end %> <% end %>
</select> </select>
<% end %> <% end %>

View file

@ -1,7 +1,7 @@
<% content_for "header" do %> <% content_for "header" do %>
<meta name="description" content="<%= translate(locale, "An alternative front-end to YouTube") %>"> <meta name="description" content="<%= translate(locale, "An alternative front-end to YouTube") %>">
<title> <title>
<% if config.default_home != "Top" %> <% if env.get("preferences").as(Preferences).default_home != "Top" %>
<%= translate(locale, "Top") %> - Invidious <%= translate(locale, "Top") %> - Invidious
<% else %> <% else %>
Invidious Invidious

View file

@ -1,7 +1,7 @@
<% content_for "header" do %> <% content_for "header" do %>
<meta name="description" content="<%= translate(locale, "An alternative front-end to YouTube") %>"> <meta name="description" content="<%= translate(locale, "An alternative front-end to YouTube") %>">
<title> <title>
<% if config.default_home != "Trending" %> <% if env.get("preferences").as(Preferences).default_home != "Trending" %>
<%= translate(locale, "Trending") %> - Invidious <%= translate(locale, "Trending") %> - Invidious
<% else %> <% else %>
Invidious Invidious

View file

@ -2,6 +2,8 @@
<title><%= translate(locale, "Playlists") %> - Invidious</title> <title><%= translate(locale, "Playlists") %> - Invidious</title>
<% end %> <% end %>
<%= rendered "components/feed_menu" %>
<div class="pure-g h-box"> <div class="pure-g h-box">
<div class="pure-u-2-3"> <div class="pure-u-2-3">
<h3><%= translate(locale, "`x` playlists", %(<span id="count">#{items.size}</span>)) %></h3> <h3><%= translate(locale, "`x` playlists", %(<span id="count">#{items.size}</span>)) %></h3>