mirror of
https://github.com/iv-org/invidious.git
synced 2025-12-03 12:28:29 -06:00
feat: Add support for POST requests on searches for privacy
This commit is contained in:
parent
35d1d499bc
commit
4abb3c7198
@ -124,6 +124,8 @@
|
||||
"preferences_sort_label": "Sort videos by: ",
|
||||
"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 to be saved in your browser history.",
|
||||
"published": "published",
|
||||
"published - reverse": "published - reverse",
|
||||
"alphabetically": "alphabetically",
|
||||
|
||||
@ -54,6 +54,7 @@ struct ConfigPreferences
|
||||
property save_player_pos : Bool = false
|
||||
@[YAML::Field(ignore: true)]
|
||||
property default_playlist : String? = nil
|
||||
property search_privacy : Bool = false
|
||||
|
||||
def to_tuple
|
||||
{% begin %}
|
||||
|
||||
@ -145,6 +145,10 @@ module Invidious::Routes::PreferencesRoute
|
||||
|
||||
default_playlist = env.params.body["default_playlist"]?.try &.as(String)
|
||||
|
||||
search_privacy = env.params.body["search_privacy"]?.try &.as(String)
|
||||
search_privacy ||= "off"
|
||||
search_privacy = search_privacy == "on"
|
||||
|
||||
# Convert to JSON and back again to take advantage of converters used for compatibility
|
||||
preferences = Preferences.from_json({
|
||||
annotations: annotations,
|
||||
@ -182,6 +186,7 @@ module Invidious::Routes::PreferencesRoute
|
||||
show_nick: show_nick,
|
||||
save_player_pos: save_player_pos,
|
||||
default_playlist: default_playlist,
|
||||
search_privacy: search_privacy,
|
||||
}.to_json)
|
||||
|
||||
if user = env.get? "user"
|
||||
|
||||
@ -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
|
||||
|
||||
@ -185,6 +185,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
|
||||
|
||||
|
||||
@ -57,6 +57,7 @@ struct Preferences
|
||||
property volume : Int32 = CONFIG.default_user_preferences.volume
|
||||
property save_player_pos : Bool = CONFIG.default_user_preferences.save_player_pos
|
||||
property default_playlist : String? = nil
|
||||
property search_privacy : Bool = CONFIG.default_user_preferences.search_privacy
|
||||
|
||||
module BoolToString
|
||||
def self.to_json(value : String, json : JSON::Builder)
|
||||
|
||||
@ -1,4 +1,12 @@
|
||||
<%
|
||||
search_privacy = env.get("preferences").as(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 %>
|
||||
|
||||
@ -1,5 +1,10 @@
|
||||
<%
|
||||
search_privacy = env.get("preferences").as(Preferences).search_privacy
|
||||
search_query = query.text.size > 30 ? HTML.escape(query.text[0,30].rstrip(".")) + "…" : HTML.escape(query.text)
|
||||
%>
|
||||
|
||||
<% content_for "header" do %>
|
||||
<title><%= query.text.size > 30 ? HTML.escape(query.text[0,30].rstrip(".")) + "…" : 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 %>
|
||||
|
||||
|
||||
@ -221,6 +221,12 @@
|
||||
<input name="automatic_instance_redirect" id="automatic_instance_redirect" type="checkbox" <% if preferences.automatic_instance_redirect %>checked<% end %>>
|
||||
</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 %>>
|
||||
<label for="search_privacy"><%= translate(locale, "preferences_search_privacy_description") %></label>
|
||||
</div>
|
||||
|
||||
<% if env.get? "user" %>
|
||||
<legend><%= translate(locale, "preferences_category_subscription") %></legend>
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user