feat: Add support for POST requests on searches for privacy

Use already set preferences variable

Use span for description, grammar fix from Copilot
This commit is contained in:
Fijxu
2025-11-30 17:07:17 -03:00
parent 9ab8d39168
commit f01428b07c
9 changed files with 39 additions and 8 deletions

View File

@@ -663,7 +663,7 @@ span > select {
background: #f2f2f2;
color: #7c7c7c;
}
.no-theme footer #footer-custom-text > b {
color: #565D64;
}
@@ -750,7 +750,7 @@ body.dark-theme {
.dark-theme #footer-content-container > hr {
color: #313131;
}
}
.dark-theme .footer-content #footer-custom-text > b {
color: #ccc;
@@ -1025,7 +1025,7 @@ h1, h2, h3, h4, h5, p,
.video-transcript header {
padding-bottom: 5px;
border-bottom: 1px solid #a0a0a0;
}
}
.video-transcript > #lines {
display: flex;
@@ -1082,4 +1082,4 @@ h1, h2, h3, h4, h5, p,
padding-left: 10px;
display: inline-block;
vertical-align: top;
}
}

View File

@@ -129,6 +129,8 @@
"preferences_default_trending_type": "Default trending page: ",
"preferences_default_playlist": "Default playlist: ",
"preferences_default_playlist_none": "No default playlist set",
"preferences_search_privacy_label": "Search privacy: ",
"preferences_search_privacy_description": "Enabling this preference will prevent your search queries from being saved in your browser history.",
"published": "published",
"published - reverse": "published - reverse",
"alphabetically": "alphabetically",

View File

@@ -62,6 +62,7 @@ struct ConfigPreferences
property show_community_backends : Bool = false
@[YAML::Field(ignore: true)]
property current_companion : Int32? = nil
property search_privacy : Bool = false
def to_tuple
{% begin %}

View File

@@ -40,9 +40,16 @@ module Invidious::Routes::Search
preferences = env.get("preferences").as(Preferences)
locale = preferences.locale
region = env.params.query["region"]? || preferences.region
uri_params = URI::Params.new
if env.request.method == "GET"
uri_params = env.params.query
else
uri_params = env.params.body
end
query = Invidious::Search::Query.new(env.params.query, :regular, region)
region = uri_params["region"]? || preferences.region
query = Invidious::Search::Query.new(uri_params, :regular, region)
if query.empty?
# Display the full page search box implemented in #1977

View File

@@ -188,6 +188,7 @@ module Invidious::Routing
get "/opensearch.xml", Routes::Search, :opensearch
get "/results", Routes::Search, :results
get "/search", Routes::Search, :search
post "/search", Routes::Search, :search
get "/hashtag/:hashtag", Routes::Search, :hashtag
end

View File

@@ -61,6 +61,7 @@ struct Preferences
property default_playlist : String? = nil
property show_community_backends : Bool = false
property current_companion : Int32? = nil
property search_privacy : Bool = CONFIG.default_user_preferences.search_privacy
module BoolToString
def self.to_json(value : String, json : JSON::Builder)

View File

@@ -1,4 +1,12 @@
<%
search_privacy = preferences.search_privacy
%>
<% if search_privacy %>
<form class="pure-form" action="/search" method="post">
<% else %>
<form class="pure-form" action="/search" method="get">
<% end %>
<fieldset>
<input type="search" id="searchbox" autocorrect="off"
autocapitalize="none" spellcheck="false" <% if autofocus %>autofocus<% end %>

View File

@@ -1,5 +1,10 @@
<%
search_privacy = preferences.search_privacy
search_query = query.text.size > 30 ? HTML.escape(query.text[0,30].rstrip(".")) + "&hellip;" : HTML.escape(query.text)
%>
<% content_for "header" do %>
<title><%= query.text.size > 30 ? HTML.escape(query.text[0,30].rstrip(".")) + "&hellip;" : HTML.escape(query.text) %> - Invidious</title>
<title><%= search_privacy ? "Search" : search_query %> - Invidious</title>
<link rel="stylesheet" href="/css/search.css?v=<%= ASSET_COMMIT %>">
<% end %>

View File

@@ -241,6 +241,12 @@
<span class="preference-description"><%= translate(locale, "preferences_show_community_backends_description") %></span>
</div>
<div class="pure-control-group">
<label for="search_privacy"><%= translate(locale, "preferences_search_privacy_label") %></label>
<input name="search_privacy" id="search_privacy" type="checkbox" <% if preferences.search_privacy %>checked<% end %>>
<span class="preference-description"><%= translate(locale, "preferences_search_privacy_description") %></span>
</div>
<div class="pure-control-group">
<label for="hidden_channels"><%= translate(locale, "preferences_hidden_channels") %></label>
<% hidden_channels = preferences.hidden_channels %>
@@ -406,4 +412,4 @@
</form>
</div>
<div id="footer_buffer"></div>
<div id="footer_buffer"></div>