mirror of
https://github.com/iv-org/invidious.git
synced 2025-03-13 09:26:35 -04:00
Merge b4f8a6726ba6f0e8876e0ae0fb1b7ca41f3a47a7 into adcdb8cb92bbf61bac46102eff026593d0bc87b0
This commit is contained in:
commit
5833708824
@ -264,12 +264,13 @@ https_only: false
|
||||
# -----------------------------
|
||||
|
||||
##
|
||||
## Enable/Disable the "Popular" tab on the main page.
|
||||
## Enable/Disable specific pages on the main page.
|
||||
##
|
||||
## Accepted values: true, false
|
||||
## Default: true
|
||||
#pages_enabled:
|
||||
# trending: true
|
||||
# popular: true
|
||||
# search: true
|
||||
##
|
||||
#popular_enabled: true
|
||||
|
||||
##
|
||||
## Enable/Disable statstics (available at /api/v1/stats).
|
||||
|
@ -501,5 +501,7 @@
|
||||
"toggle_theme": "Toggle Theme",
|
||||
"carousel_slide": "Slide {{current}} of {{total}}",
|
||||
"carousel_skip": "Skip the Carousel",
|
||||
"carousel_go_to": "Go to slide `x`"
|
||||
"carousel_go_to": "Go to slide `x`",
|
||||
"preferences_trending_enabled_label": "Trending enabled: ",
|
||||
"preferences_search_enabled_label": "Search enabled: "
|
||||
}
|
||||
|
@ -188,7 +188,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
|
||||
|
||||
|
@ -107,7 +107,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 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
|
||||
@ -182,6 +182,10 @@ 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"
|
||||
|
@ -4,6 +4,11 @@ module Invidious::Routes::API::V1::Feeds
|
||||
|
||||
env.response.content_type = "application/json"
|
||||
|
||||
if !CONFIG.page_enabled?("trending")
|
||||
error_message = {"error" => "Administrator has disabled this endpoint."}.to_json
|
||||
haltf env, 403, error_message
|
||||
end
|
||||
|
||||
region = env.params.query["region"]?
|
||||
trending_type = env.params.query["type"]?
|
||||
|
||||
@ -29,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
|
||||
|
@ -5,6 +5,11 @@ module Invidious::Routes::API::V1::Search
|
||||
|
||||
env.response.content_type = "application/json"
|
||||
|
||||
if !CONFIG.page_enabled?("search")
|
||||
error_message = {"error" => "Administrator has disabled this endpoint."}.to_json
|
||||
haltf env, 403, error_message
|
||||
end
|
||||
|
||||
query = Invidious::Search::Query.new(env.params.query, :regular, region)
|
||||
|
||||
begin
|
||||
|
@ -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,19 +45,24 @@ module Invidious::Routes::Feeds
|
||||
def self.trending(env)
|
||||
locale = env.get("preferences").as(Preferences).locale
|
||||
|
||||
trending_type = env.params.query["type"]?
|
||||
trending_type ||= "Default"
|
||||
if CONFIG.page_enabled?("trending")
|
||||
trending_type = env.params.query["type"]?
|
||||
trending_type ||= "Default"
|
||||
|
||||
region = env.params.query["region"]?
|
||||
region ||= env.get("preferences").as(Preferences).region
|
||||
region = env.params.query["region"]?
|
||||
region ||= env.get("preferences").as(Preferences).region
|
||||
|
||||
begin
|
||||
trending, plid = fetch_trending(trending_type, region, locale)
|
||||
rescue ex
|
||||
return error_template(500, ex)
|
||||
begin
|
||||
trending, plid = fetch_trending(trending_type, region, locale)
|
||||
rescue ex
|
||||
return error_template(500, ex)
|
||||
end
|
||||
|
||||
templated "feeds/trending"
|
||||
else
|
||||
message = translate(locale, "The Trending feed has been disabled by the administrator.")
|
||||
templated "message"
|
||||
end
|
||||
|
||||
templated "feeds/trending"
|
||||
end
|
||||
|
||||
def self.subscriptions(env)
|
||||
|
@ -199,9 +199,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"
|
||||
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"
|
||||
|
@ -40,47 +40,46 @@ module Invidious::Routes::Search
|
||||
prefs = env.get("preferences").as(Preferences)
|
||||
locale = prefs.locale
|
||||
|
||||
region = env.params.query["region"]? || prefs.region
|
||||
if CONFIG.page_enabled?("search")
|
||||
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)
|
||||
|
||||
if query.empty?
|
||||
# Display the full page search box implemented in #1977
|
||||
env.set "search", ""
|
||||
templated "search_homepage", navbar_search: false
|
||||
else
|
||||
user = env.get? "user"
|
||||
|
||||
# An URL was copy/pasted in the search box.
|
||||
# Redirect the user to the appropriate page.
|
||||
if query.url?
|
||||
return env.redirect UrlSanitizer.process(query.text).to_s
|
||||
end
|
||||
|
||||
begin
|
||||
items = query.process
|
||||
rescue ex : ChannelSearchException
|
||||
return error_template(404, "Unable to find channel with id of '#{HTML.escape(ex.channel)}'. Are you sure that's an actual channel id? It should look like 'UC4QobU6STFB0P71PMvOGN5A'.")
|
||||
rescue ex
|
||||
return error_template(500, ex)
|
||||
end
|
||||
|
||||
redirect_url = Invidious::Frontend::Misc.redirect_url(env)
|
||||
|
||||
# Pagination
|
||||
page_nav_html = Frontend::Pagination.nav_numeric(locale,
|
||||
base_url: "/search?#{query.to_http_params}",
|
||||
current_page: query.page,
|
||||
show_next: (items.size >= 20)
|
||||
)
|
||||
|
||||
if query.type == Invidious::Search::Query::Type::Channel
|
||||
env.set "search", "channel:#{query.channel} #{query.text}"
|
||||
if query.empty?
|
||||
# Display the full page search box implemented in #1977
|
||||
env.set "search", ""
|
||||
templated "search_homepage", navbar_search: false
|
||||
else
|
||||
env.set "search", query.text
|
||||
end
|
||||
user = env.get? "user"
|
||||
|
||||
templated "search"
|
||||
begin
|
||||
items = query.process
|
||||
rescue ex : ChannelSearchException
|
||||
return error_template(404, "Unable to find channel with id of '#{HTML.escape(ex.channel)}'. Are you sure that's an actual channel id? It should look like 'UC4QobU6STFB0P71PMvOGN5A'.")
|
||||
rescue ex
|
||||
return error_template(500, ex)
|
||||
end
|
||||
|
||||
redirect_url = Invidious::Frontend::Misc.redirect_url(env)
|
||||
|
||||
# Pagination
|
||||
page_nav_html = Frontend::Pagination.nav_numeric(locale,
|
||||
base_url: "/search?#{query.to_http_params}",
|
||||
current_page: query.page,
|
||||
show_next: (items.size >= 20)
|
||||
)
|
||||
|
||||
if query.type == Invidious::Search::Query::Type::Channel
|
||||
env.set "search", "channel:#{query.channel} #{query.text}"
|
||||
else
|
||||
env.set "search", query.text
|
||||
end
|
||||
|
||||
templated "search"
|
||||
end
|
||||
else
|
||||
message = translate(locale, "Search has been disabled by the administrator.")
|
||||
templated "message"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -289,9 +289,18 @@
|
||||
|
||||
<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, "preferences_trending_enabled_label") %></label>
|
||||
<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, "preferences_search_enabled_label") %></label>
|
||||
<input name="search_enabled" id="search_enabled" type="checkbox" <% if CONFIG.page_enabled?("search") %>checked<% end %>>
|
||||
</div>
|
||||
|
||||
<div class="pure-control-group">
|
||||
<label for="captcha_enabled"><%= translate(locale, "CAPTCHA enabled: ") %></label>
|
||||
|
Loading…
x
Reference in New Issue
Block a user