Add instance redirect on empty/broken search

This commit is contained in:
syeopite 2021-03-26 21:22:46 -07:00
parent 37ff2ac2b9
commit 311e7684b2
No known key found for this signature in database
GPG Key ID: 6FA616E5A5294A82
4 changed files with 111 additions and 98 deletions

View File

@ -162,6 +162,7 @@
"Show less": "Show less", "Show less": "Show less",
"Watch on YouTube": "Watch on YouTube", "Watch on YouTube": "Watch on YouTube",
"Switch Invidious Instance": "Switch Invidious Instance", "Switch Invidious Instance": "Switch Invidious Instance",
"Broken?": "Broken?",
"Hide annotations": "Hide annotations", "Hide annotations": "Hide annotations",
"Show annotations": "Show annotations", "Show annotations": "Show annotations",
"Genre: ": "Genre: ", "Genre: ": "Genre: ",

View File

@ -410,7 +410,7 @@ def convert_theme(theme)
end end
end end
def fetch_random_instance() def fetch_random_instance
instance_list = HTTP::Client.get "https://api.invidious.io/instances.json" instance_list = HTTP::Client.get "https://api.invidious.io/instances.json"
instance_list = JSON.parse(instance_list.body) instance_list = JSON.parse(instance_list.body)

View File

@ -37,8 +37,13 @@ class Invidious::Routes::Misc < Invidious::Routes::BaseRoute
end end
def cross_instance_redirect(env) def cross_instance_redirect(env)
id = env.params.query["id"]
instance_url = fetch_random_instance instance_url = fetch_random_instance
if env.params.query["id"]?
id = env.params.query["id"]
env.redirect "https://#{instance_url}/watch?v=#{id}" env.redirect "https://#{instance_url}/watch?v=#{id}"
elsif env.params.query["q"]?
query, page = env.params.query["q"], env.params.query["page"]
env.redirect "https://#{instance_url}/search?q=#{query}&page=#{page}"
end
end end
end end

View File

@ -2,6 +2,12 @@
<title><%= search_query.not_nil!.size > 30 ? HTML.escape(query.not_nil![0,30].rstrip(".") + "...") : HTML.escape(query.not_nil!) %> - Invidious</title> <title><%= search_query.not_nil!.size > 30 ? HTML.escape(query.not_nil![0,30].rstrip(".") + "...") : HTML.escape(query.not_nil!) %> - Invidious</title>
<% end %> <% end %>
<!-- Search redirection and filtering UI -->
<% if count == 0 %>
<h3 style="text-align: center">
<%= translate(locale, "Broken?") %> <a href="/redirect?q=<%= HTML.escape(query.not_nil!) %>&page=<%= page + 1 %>"><%= translate(locale, "Switch Invidious Instance") %></a>
</h3>
<% else %>
<details id="filters"> <details id="filters">
<summary> <summary>
<h3 style="display:inline"> <%= translate(locale, "filter") %> </h3> <h3 style="display:inline"> <%= translate(locale, "filter") %> </h3>
@ -88,6 +94,7 @@
</div> </div>
</div> </div>
</details> </details>
<% end %>
<hr/> <hr/>