mirror of
https://github.com/iv-org/invidious.git
synced 2024-11-25 15:07:22 +00:00
Add instance redirect on empty/broken search
This commit is contained in:
parent
37ff2ac2b9
commit
311e7684b2
@ -162,6 +162,7 @@
|
||||
"Show less": "Show less",
|
||||
"Watch on YouTube": "Watch on YouTube",
|
||||
"Switch Invidious Instance": "Switch Invidious Instance",
|
||||
"Broken?": "Broken?",
|
||||
"Hide annotations": "Hide annotations",
|
||||
"Show annotations": "Show annotations",
|
||||
"Genre: ": "Genre: ",
|
||||
|
@ -410,7 +410,7 @@ def convert_theme(theme)
|
||||
end
|
||||
end
|
||||
|
||||
def fetch_random_instance()
|
||||
def fetch_random_instance
|
||||
instance_list = HTTP::Client.get "https://api.invidious.io/instances.json"
|
||||
instance_list = JSON.parse(instance_list.body)
|
||||
|
||||
|
@ -37,8 +37,13 @@ class Invidious::Routes::Misc < Invidious::Routes::BaseRoute
|
||||
end
|
||||
|
||||
def cross_instance_redirect(env)
|
||||
id = env.params.query["id"]
|
||||
instance_url = fetch_random_instance
|
||||
if env.params.query["id"]?
|
||||
id = env.params.query["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
|
||||
|
@ -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>
|
||||
<% 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">
|
||||
<summary>
|
||||
<h3 style="display:inline"> <%= translate(locale, "filter") %> </h3>
|
||||
@ -88,6 +94,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</details>
|
||||
<% end %>
|
||||
|
||||
<hr/>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user