feat: add search_page_disabled locale + preferences page filtering + debug config route

- Fix kemal_static_file_handler directory_listing to use Path types (Crystal API compat)
- Add missing search_page_disabled translation key to en-US.json
- Filter preferences default_home options based on pages_enabled config
- Add admin-only /debug_config route for verifying configuration state
This commit is contained in:
Richard Lora 2026-02-28 19:01:35 -05:00
parent 2933c7e2f4
commit bd6dd9cb55
4 changed files with 641 additions and 517 deletions

File diff suppressed because it is too large Load Diff

View File

@ -185,7 +185,7 @@ module Kemal
if is_dir
if config.is_a?(Hash) && config["dir_listing"] == true
context.response.content_type = "text/html"
directory_listing(context.response, request_path, file_path)
directory_listing(context.response, Path[request_path], Path[file_path])
else
call_next(context)
end

View File

@ -0,0 +1,114 @@
# Debug route to verify configuration is loaded correctly
# This can help diagnose issues with pages_enabled configuration
module Invidious::Routes::DebugConfig
def self.show(env)
# Only allow access to admins or in development mode
if CONFIG.admins.empty? || (user = env.get? "user")
admin_user = user.try &.as(User)
if !admin_user || !CONFIG.admins.includes?(admin_user.email)
return error_template(403, "Administrator privileges required")
end
else
# If no user is logged in and admins are configured, deny access
return error_template(403, "Administrator privileges required")
end
html = <<-HTML
<!DOCTYPE html>
<html>
<head>
<title>Configuration Debug - Invidious</title>
<style>
body { font-family: monospace; padding: 20px; }
.enabled { color: green; }
.disabled { color: red; }
table { border-collapse: collapse; margin: 20px 0; }
td, th { border: 1px solid #ccc; padding: 8px; text-align: left; }
th { background: #f0f0f0; }
pre { background: #f5f5f5; padding: 10px; overflow-x: auto; }
</style>
</head>
<body>
<h1>Invidious Configuration Debug</h1>
<h2>Pages Configuration</h2>
<table>
<tr>
<th>Page</th>
<th>Status</th>
<th>Configuration Value</th>
</tr>
<tr>
<td>Popular</td>
<td class="#{CONFIG.page_enabled?("popular") ? "enabled" : "disabled"}">
#{CONFIG.page_enabled?("popular") ? "ENABLED" : "DISABLED"}
</td>
<td>#{CONFIG.pages_enabled.popular}</td>
</tr>
<tr>
<td>Trending</td>
<td class="#{CONFIG.page_enabled?("trending") ? "enabled" : "disabled"}">
#{CONFIG.page_enabled?("trending") ? "ENABLED" : "DISABLED"}
</td>
<td>#{CONFIG.pages_enabled.trending}</td>
</tr>
<tr>
<td>Search</td>
<td class="#{CONFIG.page_enabled?("search") ? "enabled" : "disabled"}">
#{CONFIG.page_enabled?("search") ? "ENABLED" : "DISABLED"}
</td>
<td>#{CONFIG.pages_enabled.search}</td>
</tr>
</table>
<h2>Configuration Flags</h2>
<table>
<tr>
<th>Flag</th>
<th>Value</th>
</tr>
<tr>
<td>pages_enabled_present</td>
<td>#{CONFIG.pages_enabled_present}</td>
</tr>
<tr>
<td>popular_enabled_present (deprecated)</td>
<td>#{CONFIG.popular_enabled_present}</td>
</tr>
<tr>
<td>popular_enabled (deprecated)</td>
<td>#{CONFIG.popular_enabled}</td>
</tr>
</table>
<h2>Blocked Routes</h2>
<p>The following routes should be blocked based on current configuration:</p>
<ul>
#{!CONFIG.page_enabled?("popular") ? "<li>/feed/popular</li><li>/api/v1/popular</li>" : ""}
#{!CONFIG.page_enabled?("trending") ? "<li>/feed/trending</li><li>/api/v1/trending</li>" : ""}
#{!CONFIG.page_enabled?("search") ? "<li>/search</li><li>/api/v1/search</li>" : ""}
</ul>
<h2>Test Links</h2>
<p>Click these links to verify they are properly blocked:</p>
<ul>
<li><a href="/feed/popular">/feed/popular</a> - #{CONFIG.page_enabled?("popular") ? "Should work" : "Should be blocked"}</li>
<li><a href="/feed/trending">/feed/trending</a> - #{CONFIG.page_enabled?("trending") ? "Should work" : "Should be blocked"}</li>
<li><a href="/search">/search</a> - #{CONFIG.page_enabled?("search") ? "Should work" : "Should be blocked"}</li>
</ul>
<h2>Raw Configuration</h2>
<pre>pages_enabled: #{CONFIG.pages_enabled.inspect}</pre>
<h2>Environment Check</h2>
<pre>INVIDIOUS_CONFIG present: #{ENV.has_key?("INVIDIOUS_CONFIG")}</pre>
<pre>INVIDIOUS_PAGES_ENABLED present: #{ENV.has_key?("INVIDIOUS_PAGES_ENABLED")}</pre>
</body>
</html>
HTML
env.response.content_type = "text/html"
env.response.print html
end
end

View File

@ -182,11 +182,20 @@
<input name="thin_mode" id="thin_mode" type="checkbox" <% if preferences.thin_mode %>checked<% end %>>
</div>
<% if env.get?("user") %>
<% feed_options = {"", "Popular", "Trending", "Subscriptions", "Playlists"} %>
<% else %>
<% feed_options = {"", "Popular", "Trending"} %>
<% end %>
<%
# Build feed options based on enabled pages
feed_options = [] of String
# Empty string represents Search page
feed_options << "" if CONFIG.page_enabled?("search")
feed_options << "Popular" if CONFIG.page_enabled?("popular")
feed_options << "Trending" if CONFIG.page_enabled?("trending")
if env.get?("user")
feed_options << "Subscriptions"
feed_options << "Playlists"
end
# Always add "none" option as fallback
feed_options << "<none>" if !feed_options.includes?("<none>")
%>
<div class="pure-control-group">
<label for="default_home"><%= translate(locale, "preferences_default_home_label") %></label>