Skip to content

Commit 9c19a18

Browse files
committed
feat: Add support for POST requests on searches for privacy
1 parent b2ecd8a commit 9c19a18

File tree

9 files changed

+39
-3
lines changed

9 files changed

+39
-3
lines changed

locales/en-US.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@
124124
"preferences_sort_label": "Sort videos by: ",
125125
"preferences_default_playlist": "Default playlist: ",
126126
"preferences_default_playlist_none": "No default playlist set",
127+
"preferences_search_privacy_label": "Search privacy: ",
128+
"preferences_search_privacy_description": "Enabling this preference will prevent your search queries to be saved in your browser history.",
127129
"published": "published",
128130
"published - reverse": "published - reverse",
129131
"alphabetically": "alphabetically",

src/invidious/config.cr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ struct ConfigPreferences
5454
property save_player_pos : Bool = false
5555
@[YAML::Field(ignore: true)]
5656
property default_playlist : String? = nil
57+
property search_privacy : Bool = false
5758

5859
def to_tuple
5960
{% begin %}

src/invidious/routes/preferences.cr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ module Invidious::Routes::PreferencesRoute
146146

147147
default_playlist = env.params.body["default_playlist"]?.try &.as(String)
148148

149+
search_privacy = env.params.body["search_privacy"]?.try &.as(String)
150+
search_privacy ||= "off"
151+
search_privacy = search_privacy == "on"
152+
149153
# Convert to JSON and back again to take advantage of converters used for compatibility
150154
preferences = Preferences.from_json({
151155
annotations: annotations,
@@ -183,6 +187,7 @@ module Invidious::Routes::PreferencesRoute
183187
show_nick: show_nick,
184188
save_player_pos: save_player_pos,
185189
default_playlist: default_playlist,
190+
search_privacy: search_privacy,
186191
}.to_json)
187192

188193
if user = env.get? "user"

src/invidious/routes/search.cr

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,16 @@ module Invidious::Routes::Search
4040
prefs = env.get("preferences").as(Preferences)
4141
locale = prefs.locale
4242

43-
region = env.params.query["region"]? || prefs.region
43+
uri_params = URI::Params.new
44+
if env.request.method == "GET"
45+
uri_params = env.params.query
46+
else
47+
uri_params = env.params.body
48+
end
49+
50+
region = uri_params["region"]? || prefs.region
4451

45-
query = Invidious::Search::Query.new(env.params.query, :regular, region)
52+
query = Invidious::Search::Query.new(uri_params, :regular, region)
4653

4754
if query.empty?
4855
# Display the full page search box implemented in #1977

src/invidious/routing.cr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ module Invidious::Routing
185185
get "/opensearch.xml", Routes::Search, :opensearch
186186
get "/results", Routes::Search, :results
187187
get "/search", Routes::Search, :search
188+
post "/search", Routes::Search, :search
188189
get "/hashtag/:hashtag", Routes::Search, :hashtag
189190
end
190191

src/invidious/user/preferences.cr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ struct Preferences
5757
property volume : Int32 = CONFIG.default_user_preferences.volume
5858
property save_player_pos : Bool = CONFIG.default_user_preferences.save_player_pos
5959
property default_playlist : String? = nil
60+
property search_privacy : Bool = CONFIG.default_user_preferences.search_privacy
6061

6162
module BoolToString
6263
def self.to_json(value : String, json : JSON::Builder)

src/invidious/views/components/search_box.ecr

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1+
<%
2+
search_privacy = env.get("preferences").as(Preferences).search_privacy
3+
%>
4+
5+
<% if search_privacy %>
6+
<form class="pure-form" action="/search" method="post">
7+
<% else %>
18
<form class="pure-form" action="/search" method="get">
9+
<% end %>
210
<fieldset>
311
<input type="search" id="searchbox" autocorrect="off"
412
autocapitalize="none" spellcheck="false" <% if autofocus %>autofocus<% end %>

src/invidious/views/search.ecr

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
<%
2+
search_privacy = env.get("preferences").as(Preferences).search_privacy
3+
search_query = query.text.size > 30 ? HTML.escape(query.text[0,30].rstrip(".")) + "&hellip;" : HTML.escape(query.text)
4+
%>
5+
16
<% content_for "header" do %>
2-
<title><%= query.text.size > 30 ? HTML.escape(query.text[0,30].rstrip(".")) + "&hellip;" : HTML.escape(query.text) %> - Invidious</title>
7+
<title><%= search_privacy ? "Search" : search_query %> - Invidious</title>
38
<link rel="stylesheet" href="/css/search.css?v=<%= ASSET_COMMIT %>">
49
<% end %>
510

src/invidious/views/user/preferences.ecr

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,12 @@
221221
<input name="automatic_instance_redirect" id="automatic_instance_redirect" type="checkbox" <% if preferences.automatic_instance_redirect %>checked<% end %>>
222222
</div>
223223

224+
<div class="pure-control-group">
225+
<label for="search_privacy"><%= translate(locale, "preferences_search_privacy_label") %></label>
226+
<input name="search_privacy" id="search_privacy" type="checkbox" <% if preferences.search_privacy %>checked<% end %>>
227+
<label for="search_privacy"><%= translate(locale, "preferences_search_privacy_description") %></label>
228+
</div>
229+
224230
<% if env.get? "user" %>
225231
<legend><%= translate(locale, "preferences_category_subscription") %></legend>
226232

0 commit comments

Comments
 (0)