Add `popular-enabled` option

This is similar to the removed `top-enabled` option but for the Popular feed.
The instance needs to be restarted if the feed was enabled.

Editing admin options on the preferences page is also fixed.

The handling of the feed pages now only happens in a single place.

Instead of redirecting:
  - The Top feed now displays a message that it was removed from Invidious.
  - The Popular feed now displays a message that it was disabled if it was.
pull/1609/head
saltycrys 4 years ago
parent dba7dc4e96
commit 198dfffaeb

@ -162,13 +162,16 @@ end
Invidious::Jobs.register Invidious::Jobs::RefreshChannelsJob.new(PG_DB, logger, config) Invidious::Jobs.register Invidious::Jobs::RefreshChannelsJob.new(PG_DB, logger, config)
Invidious::Jobs.register Invidious::Jobs::RefreshFeedsJob.new(PG_DB, logger, config) Invidious::Jobs.register Invidious::Jobs::RefreshFeedsJob.new(PG_DB, logger, config)
Invidious::Jobs.register Invidious::Jobs::SubscribeToFeedsJob.new(PG_DB, logger, config, HMAC_KEY) Invidious::Jobs.register Invidious::Jobs::SubscribeToFeedsJob.new(PG_DB, logger, config, HMAC_KEY)
Invidious::Jobs.register Invidious::Jobs::PullPopularVideosJob.new(PG_DB)
Invidious::Jobs.register Invidious::Jobs::UpdateDecryptFunctionJob.new Invidious::Jobs.register Invidious::Jobs::UpdateDecryptFunctionJob.new
if config.statistics_enabled if config.statistics_enabled
Invidious::Jobs.register Invidious::Jobs::StatisticsRefreshJob.new(PG_DB, config, SOFTWARE) Invidious::Jobs.register Invidious::Jobs::StatisticsRefreshJob.new(PG_DB, config, SOFTWARE)
end end
if config.popular_enabled
Invidious::Jobs.register Invidious::Jobs::PullPopularVideosJob.new(PG_DB)
end
if config.captcha_key if config.captcha_key
Invidious::Jobs.register Invidious::Jobs::BypassCaptchaJob.new(logger, config) Invidious::Jobs.register Invidious::Jobs::BypassCaptchaJob.new(logger, config)
end end
@ -1140,13 +1143,20 @@ end
get "/feed/top" do |env| get "/feed/top" do |env|
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = LOCALES[env.get("preferences").as(Preferences).locale]?
env.redirect "/"
message = translate(locale, "The Top feed has been removed from Invidious.")
templated "message"
end end
get "/feed/popular" do |env| get "/feed/popular" do |env|
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = LOCALES[env.get("preferences").as(Preferences).locale]?
if config.popular_enabled
templated "popular" templated "popular"
else
message = translate(locale, "The Popular feed has been disabled by the administrator.")
templated "message"
end
end end
get "/feed/trending" do |env| get "/feed/trending" do |env|
@ -2210,6 +2220,12 @@ get "/api/v1/popular" do |env|
env.response.content_type = "application/json" env.response.content_type = "application/json"
if !config.popular_enabled
error_message = {"error" => "Administrator has disabled this endpoint."}.to_json
env.response.status_code = 400
next error_message
end
JSON.build do |json| JSON.build do |json|
json.array do json.array do
popular_videos.each do |video| popular_videos.each do |video|
@ -2223,7 +2239,8 @@ get "/api/v1/top" do |env|
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = LOCALES[env.get("preferences").as(Preferences).locale]?
env.response.content_type = "application/json" env.response.content_type = "application/json"
"[]" env.response.status_code = 400
{"error" => "The Top feed has been removed from Invidious."}.to_json
end end
get "/api/v1/channels/:ucid" do |env| get "/api/v1/channels/:ucid" do |env|

@ -60,7 +60,7 @@ struct ConfigPreferences
end end
end end
struct Config class Config
include YAML::Serializable include YAML::Serializable
property channel_threads : Int32 # Number of threads to use for crawling videos from channels (for updating subscriptions) property channel_threads : Int32 # Number of threads to use for crawling videos from channels (for updating subscriptions)
@ -71,6 +71,7 @@ struct Config
property hmac_key : String? # HMAC signing key for CSRF tokens and verifying pubsub subscriptions property hmac_key : String? # HMAC signing key for CSRF tokens and verifying pubsub subscriptions
property domain : String? # Domain to be used for links to resources on the site where an absolute URL is required property domain : String? # Domain to be used for links to resources on the site where an absolute URL is required
property use_pubsub_feeds : Bool | Int32 = false # Subscribe to channels using PubSubHubbub (requires domain, hmac_key) property use_pubsub_feeds : Bool | Int32 = false # Subscribe to channels using PubSubHubbub (requires domain, hmac_key)
property popular_enabled : Bool = true
property captcha_enabled : Bool = true property captcha_enabled : Bool = true
property login_enabled : Bool = true property login_enabled : Bool = true
property registration_enabled : Bool = true property registration_enabled : Bool = true

@ -5,30 +5,24 @@ class Invidious::Routes::Home < Invidious::Routes::BaseRoute
user = env.get? "user" user = env.get? "user"
case preferences.default_home case preferences.default_home
when ""
templated "empty"
when "Popular" when "Popular"
templated "popular" env.redirect "/feed/popular"
when "Trending" when "Trending"
env.redirect "/feed/trending" env.redirect "/feed/trending"
when "Subscriptions" when "Subscriptions"
if user if user
env.redirect "/feed/subscriptions" env.redirect "/feed/subscriptions"
else else
templated "popular" env.redirect "/feed/popular"
end end
when "Playlists" when "Playlists"
if user if user
env.redirect "/view_all_playlists" env.redirect "/view_all_playlists"
else else
templated "popular" env.redirect "/feed/popular"
end end
else else
templated "empty" templated "empty"
end end
end end
private def popular_videos
Jobs::PullPopularVideosJob::POPULAR_VIDEOS.get
end
end end

@ -154,6 +154,10 @@ class Invidious::Routes::UserPreferences < Invidious::Routes::BaseRoute
end end
config.default_user_preferences.feed_menu = admin_feed_menu config.default_user_preferences.feed_menu = admin_feed_menu
popular_enabled = env.params.body["popular_enabled"]?.try &.as(String)
popular_enabled ||= "off"
config.popular_enabled = popular_enabled == "on"
captcha_enabled = env.params.body["captcha_enabled"]?.try &.as(String) captcha_enabled = env.params.body["captcha_enabled"]?.try &.as(String)
captcha_enabled ||= "off" captcha_enabled ||= "off"
config.captcha_enabled = captcha_enabled == "on" config.captcha_enabled = captcha_enabled == "on"

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

@ -227,6 +227,12 @@
<% end %> <% end %>
</div> </div>
<div class="pure-control-group">
<label for="popular_enabled"><%= translate(locale, "Popular enabled: ") %></label>
<input name="popular_enabled" id="popular_enabled" type="checkbox" <% if config.popular_enabled %>checked<% end %>>
</div>
<div class="pure-control-group"> <div class="pure-control-group">
<label for="captcha_enabled"><%= translate(locale, "CAPTCHA enabled: ") %></label> <label for="captcha_enabled"><%= translate(locale, "CAPTCHA enabled: ") %></label>
<input name="captcha_enabled" id="captcha_enabled" type="checkbox" <% if config.captcha_enabled %>checked<% end %>> <input name="captcha_enabled" id="captcha_enabled" type="checkbox" <% if config.captcha_enabled %>checked<% end %>>

Loading…
Cancel
Save