feat(invidious): specific pages are disabled with the use of an array

This commit is contained in:
Richard Lora 2024-06-30 18:05:26 -04:00
parent e0f20b0641
commit da422fae05
9 changed files with 30 additions and 47 deletions

View File

@ -203,28 +203,13 @@ https_only: false
# ----------------------------- # -----------------------------
## ##
## Enable/Disable the "Popular" tab on the main page. ## Enable/Disable specific pages on the main page.
## Example:
## pages_enabled:
## trending: true
## popular: true
## search: true
## ##
## Accepted values: true, false
## Default: true
##
#popular_enabled: true
##
## Enable/Disable the "Trending" tab on the main page.
##
## Accepted values: true, false
## Default: true
##
#trending_enabled: true
##
## Enable/Disable "Search" on the main page.
##
## Accepted values: true, false
## Default: true
##
#search_enabled: true
## ##
## Enable/Disable statstics (available at /api/v1/stats). ## Enable/Disable statstics (available at /api/v1/stats).

View File

@ -176,7 +176,7 @@ if (CONFIG.use_pubsub_feeds.is_a?(Bool) && CONFIG.use_pubsub_feeds.as(Bool)) ||
Invidious::Jobs.register Invidious::Jobs::SubscribeToFeedsJob.new(PG_DB, HMAC_KEY) Invidious::Jobs.register Invidious::Jobs::SubscribeToFeedsJob.new(PG_DB, HMAC_KEY)
end end
if CONFIG.popular_enabled if CONFIG.page_enabled?("popular")
Invidious::Jobs.register Invidious::Jobs::PullPopularVideosJob.new(PG_DB) Invidious::Jobs.register Invidious::Jobs::PullPopularVideosJob.new(PG_DB)
end end

View File

@ -90,9 +90,7 @@ class Config
property domain : String? property domain : String?
# Subscribe to channels using PubSubHubbub (requires domain, hmac_key) # Subscribe to channels using PubSubHubbub (requires domain, hmac_key)
property use_pubsub_feeds : Bool | Int32 = false property use_pubsub_feeds : Bool | Int32 = false
property popular_enabled : Bool = true property pages_enabled : Hash(String, Bool) = {"trending" => true, "popular" => true, "search" => true}
property trending_enabled : Bool = true
property search_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
@ -154,6 +152,11 @@ class Config
end end
end end
def page_enabled?(page : String) : Bool
@pages_enabled[page]? || false
end
def self.load def self.load
# Load config from file or YAML string env var # Load config from file or YAML string env var
env_config_file = "INVIDIOUS_CONFIG_FILE" env_config_file = "INVIDIOUS_CONFIG_FILE"

View File

@ -4,7 +4,7 @@ module Invidious::Routes::API::V1::Feeds
env.response.content_type = "application/json" env.response.content_type = "application/json"
if !CONFIG.trending_enabled if !CONFIG.page_enabled?("trending")
error_message = {"error" => "Administrator has disabled this endpoint."}.to_json error_message = {"error" => "Administrator has disabled this endpoint."}.to_json
haltf env, 403, error_message haltf env, 403, error_message
end end
@ -34,7 +34,7 @@ module Invidious::Routes::API::V1::Feeds
env.response.content_type = "application/json" env.response.content_type = "application/json"
if !CONFIG.popular_enabled if !CONFIG.page_enabled?("popular")
error_message = {"error" => "Administrator has disabled this endpoint."}.to_json error_message = {"error" => "Administrator has disabled this endpoint."}.to_json
haltf env, 403, error_message haltf env, 403, error_message
end end

View File

@ -5,7 +5,7 @@ module Invidious::Routes::API::V1::Search
env.response.content_type = "application/json" env.response.content_type = "application/json"
if !CONFIG.search_enabled if !CONFIG.page_enabled?("search")
error_message = {"error" => "Administrator has disabled this endpoint."}.to_json error_message = {"error" => "Administrator has disabled this endpoint."}.to_json
haltf env, 403, error_message haltf env, 403, error_message
end end

View File

@ -34,7 +34,7 @@ module Invidious::Routes::Feeds
def self.popular(env) def self.popular(env)
locale = env.get("preferences").as(Preferences).locale locale = env.get("preferences").as(Preferences).locale
if CONFIG.popular_enabled if CONFIG.page_enabled?("popular")
templated "feeds/popular" templated "feeds/popular"
else else
message = translate(locale, "The Popular feed has been disabled by the administrator.") message = translate(locale, "The Popular feed has been disabled by the administrator.")
@ -45,7 +45,7 @@ module Invidious::Routes::Feeds
def self.trending(env) def self.trending(env)
locale = env.get("preferences").as(Preferences).locale locale = env.get("preferences").as(Preferences).locale
if CONFIG.trending_enabled if CONFIG.page_enabled?("trending")
trending_type = env.params.query["type"]? trending_type = env.params.query["type"]?
trending_type ||= "Default" trending_type ||= "Default"

View File

@ -194,17 +194,12 @@ module Invidious::Routes::PreferencesRoute
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) pages_enabled = {
popular_enabled ||= "off" "popular" => (env.params.body["popular_enabled"]?.try &.as(String) || "off") == "on",
CONFIG.popular_enabled = popular_enabled == "on" "trending" => (env.params.body["trending_enabled"]?.try &.as(String) || "off") == "on",
"search" => (env.params.body["search_enabled"]?.try &.as(String) || "off") == "on"
trending_enabled = env.params.body["trending_enabled"]?.try &.as(String) }
trending_enabled ||= "off" CONFIG.pages_enabled = pages_enabled
CONFIG.trending_enabled = trending_enabled == "on"
search_enabled = env.params.body["search_enabled"]?.try &.as(String)
search_enabled ||= "off"
CONFIG.search_enabled = search_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"

View File

@ -40,7 +40,7 @@ module Invidious::Routes::Search
prefs = env.get("preferences").as(Preferences) prefs = env.get("preferences").as(Preferences)
locale = prefs.locale locale = prefs.locale
if CONFIG.search_enabled if CONFIG.page_enabled?("search")
region = env.params.query["region"]? || prefs.region region = env.params.query["region"]? || prefs.region
query = Invidious::Search::Query.new(env.params.query, :regular, region) query = Invidious::Search::Query.new(env.params.query, :regular, region)

View File

@ -284,17 +284,17 @@
<div class="pure-control-group"> <div class="pure-control-group">
<label for="popular_enabled"><%= translate(locale, "Popular enabled: ") %></label> <label for="popular_enabled"><%= translate(locale, "Popular enabled: ") %></label>
<input name="popular_enabled" id="popular_enabled" type="checkbox" <% if CONFIG.popular_enabled %>checked<% end %>> <input name="popular_enabled" id="popular_enabled" type="checkbox" <% if CONFIG.page_enabled?("popular") %>checked<% end %>>
</div> </div>
<div class="pure-control-group"> <div class="pure-control-group">
<label for="trending_enabled"><%= translate(locale, "Trending enabled: ") %></label> <label for="trending_enabled"><%= translate(locale, "Trending enabled: ") %></label>
<input name="trending_enabled" id="trending_enabled" type="checkbox" <% if CONFIG.trending_enabled %>checked<% end %>> <input name="trending_enabled" id="trending_enabled" type="checkbox" <% if CONFIG.page_enabled?("trending") %>checked<% end %>>
</div> </div>
<div class="pure-control-group"> <div class="pure-control-group">
<label for="search_enabled"><%= translate(locale, "Search enabled: ") %></label> <label for="search_enabled"><%= translate(locale, "Search enabled: ") %></label>
<input name="search_enabled" id="search_enabled" type="checkbox" <% if CONFIG.search_enabled %>checked<% end %>> <input name="search_enabled" id="search_enabled" type="checkbox" <% if CONFIG.page_enabled?("search") %>checked<% end %>>
</div> </div>
<div class="pure-control-group"> <div class="pure-control-group">