Generalize redirect route

This commit is contained in:
syeopite 2021-03-28 23:05:54 -07:00
parent 311e7684b2
commit f178297452
No known key found for this signature in database
GPG key ID: 6FA616E5A5294A82
4 changed files with 5 additions and 10 deletions

View file

@ -38,12 +38,7 @@ class Invidious::Routes::Misc < Invidious::Routes::BaseRoute
def cross_instance_redirect(env) def cross_instance_redirect(env)
instance_url = fetch_random_instance instance_url = fetch_random_instance
if env.params.query["id"]? referer = get_referer(env)
id = env.params.query["id"] env.redirect "https://#{instance_url}#{referer}"
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

@ -148,7 +148,7 @@
<a title="<%=translate(locale, "Audio mode")%>" href="/watch?v=<%= item.id %>&amp;listen=1"> <a title="<%=translate(locale, "Audio mode")%>" href="/watch?v=<%= item.id %>&amp;listen=1">
<i class="icon ion-md-headset"></i> <i class="icon ion-md-headset"></i>
</a> </a>
<a title="<%=translate(locale, "Switch Invidious Instance")%>" href="/redirect?id=<%= item.id %>&amp;listen=1"> <a title="<%=translate(locale, "Switch Invidious Instance")%>" href="/redirect?referer=<%= env.get?("current_page") %>">
<i class="icon ion-md-jet"></i> <i class="icon ion-md-jet"></i>
</a> </a>
</div> </div>

View file

@ -5,7 +5,7 @@
<!-- Search redirection and filtering UI --> <!-- Search redirection and filtering UI -->
<% if count == 0 %> <% if count == 0 %>
<h3 style="text-align: center"> <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> <%= translate(locale, "Broken?") %> <a href="/redirect?referer=<%= env.get?("current_page") %>"><%= translate(locale, "Switch Invidious Instance") %></a>
</h3> </h3>
<% else %> <% else %>
<details id="filters"> <details id="filters">

View file

@ -110,7 +110,7 @@ we're going to need to do it here in order to allow for translations.
(<a href="https://www.youtube.com/embed/<%= video.id %>"><%= translate(locale, "Embed") %></a>) (<a href="https://www.youtube.com/embed/<%= video.id %>"><%= translate(locale, "Embed") %></a>)
</span> </span>
<p id="watch-on-another-invidious-instance"> <p id="watch-on-another-invidious-instance">
<a href="/redirect?id=<%= video.id %>"><%= translate(locale, "Switch Invidious Instance") %></a> <a href="/redirect?referer=<%= env.get?("current_page") %>"><%= translate(locale, "Switch Invidious Instance") %></a>
</p> </p>
<p id="embed-link"> <p id="embed-link">
<a href="<%= embed_link %>"><%= translate(locale, "Embed Link") %></a> <a href="<%= embed_link %>"><%= translate(locale, "Embed Link") %></a>