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).

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)
end
if CONFIG.popular_enabled
if CONFIG.page_enabled?("popular")
Invidious::Jobs.register Invidious::Jobs::PullPopularVideosJob.new(PG_DB)
end

View File

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

View File

@ -4,7 +4,7 @@ module Invidious::Routes::API::V1::Feeds
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
haltf env, 403, error_message
end
@ -34,7 +34,7 @@ module Invidious::Routes::API::V1::Feeds
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
haltf env, 403, error_message
end

View File

@ -5,7 +5,7 @@ module Invidious::Routes::API::V1::Search
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
haltf env, 403, error_message
end

View File

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

View File

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

View File

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

View File

@ -284,17 +284,17 @@
<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 %>>
<input name="popular_enabled" id="popular_enabled" type="checkbox" <% if CONFIG.page_enabled?("popular") %>checked<% end %>>
</div>
<div class="pure-control-group">
<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 class="pure-control-group">
<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 class="pure-control-group">