Skip to content

Commit

Permalink
Merge pull request iv-org#2155 from SamantazFox/fix-utf8-in-search
Browse files Browse the repository at this point in the history
Multiple search fixes
  • Loading branch information
TheFrenchGhosty authored Jun 19, 2021
2 parents 3f34db5 + 3de92b3 commit 2b9c6c9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/invidious/helpers/youtube_api.cr
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ end
def request_youtube_api_search(search_query : String, params : String, region = nil)
# JSON Request data, required by the API
data = {
"query" => URI.encode_www_form(search_query),
"query" => search_query,
"context" => make_youtube_api_context(region),
"params" => params,
}
Expand Down
51 changes: 28 additions & 23 deletions src/invidious/routes/search.cr
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ class Invidious::Routes::Search < Invidious::Routes::BaseRoute

query = env.params.query["search_query"]?
query ||= env.params.query["q"]?
query ||= ""

page = env.params.query["page"]?.try &.to_i?
page ||= 1
page = env.params.query["page"]?

if query
env.redirect "/search?q=#{URI.encode_www_form(query)}&page=#{page}"
if query && !query.empty?
if page && !page.empty?
env.redirect "/search?q=" + URI.encode_www_form(query) + "&page=" + page
else
env.redirect "/search?q=" + URI.encode_www_form(query)
end
else
env.redirect "/"
env.redirect "/search"
end
end

Expand All @@ -38,28 +40,31 @@ class Invidious::Routes::Search < Invidious::Routes::BaseRoute

query = env.params.query["search_query"]?
query ||= env.params.query["q"]?
query ||= ""

return env.redirect "/" if query.empty?
if !query || query.empty?
# Display the full page search box implemented in #1977
env.set "search", ""
templated "search_homepage", navbar_search: false
else
page = env.params.query["page"]?.try &.to_i?
page ||= 1

page = env.params.query["page"]?.try &.to_i?
page ||= 1
user = env.get? "user"

user = env.get? "user"
begin
search_query, count, videos, operators = process_search_query(query, page, user, region: region)
rescue ex
return error_template(500, ex)
end

begin
search_query, count, videos, operators = process_search_query(query, page, user, region: nil)
rescue ex
return error_template(500, ex)
end
operator_hash = {} of String => String
operators.each do |operator|
key, value = operator.downcase.split(":")
operator_hash[key] = value
end

operator_hash = {} of String => String
operators.each do |operator|
key, value = operator.downcase.split(":")
operator_hash[key] = value
env.set "search", query
templated "search"
end

env.set "search", query
templated "search"
end
end
2 changes: 1 addition & 1 deletion src/invidious/views/search_homepage.ecr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<% content_for "header" do %>
<meta name="description" content="<%= translate(locale, "An alternative front-end to YouTube") %>">
<title>
Invidious
Invidious - <%= translate(locale, "search") %>
</title>
<link rel="stylesheet" href="/css/empty.css?v=<%= ASSET_COMMIT %>">
<% end %>
Expand Down

0 comments on commit 2b9c6c9

Please sign in to comment.