Add redirect buttons to error template

This commit is contained in:
syeopite 2021-05-15 22:01:46 -07:00
parent 173cd7c15e
commit b9cd40fe1e
No known key found for this signature in database
GPG key ID: 6FA616E5A5294A82
3 changed files with 42 additions and 1 deletions

View file

@ -419,5 +419,8 @@
"location": "Location", "location": "Location",
"hdr": "HDR", "hdr": "HDR",
"filter": "Filter", "filter": "Filter",
"Current version: ": "Current version: " "Current version: ": "Current version: ",
"next_steps_error_message": "After which you should try to: ",
"next_steps_error_message_refresh": "Refresh",
"next_steps_error_message_go_to_youtube": "Go to Youtube"
} }

View file

@ -40,6 +40,9 @@ def error_template_helper(env : HTTP::Server::Context, locale : Hash(String, JSO
and include the following text in your message: and include the following text in your message:
<pre style="padding: 20px; background: rgba(0, 0, 0, 0.12345);">#{issue_template}</pre> <pre style="padding: 20px; background: rgba(0, 0, 0, 0.12345);">#{issue_template}</pre>
END_HTML END_HTML
next_steps = error_redirect_helper(env, locale)
return templated "error" return templated "error"
end end
@ -47,6 +50,7 @@ def error_template_helper(env : HTTP::Server::Context, locale : Hash(String, JSO
env.response.content_type = "text/html" env.response.content_type = "text/html"
env.response.status_code = status_code env.response.status_code = status_code
error_message = translate(locale, message) error_message = translate(locale, message)
next_steps = error_redirect_helper(env, locale)
return templated "error" return templated "error"
end end
@ -103,3 +107,36 @@ end
def error_json_helper(env : HTTP::Server::Context, locale : Hash(String, JSON::Any) | Nil, status_code : Int32, message : String) def error_json_helper(env : HTTP::Server::Context, locale : Hash(String, JSON::Any) | Nil, status_code : Int32, message : String)
error_json_helper(env, locale, status_code, message, nil) error_json_helper(env, locale, status_code, message, nil)
end end
def error_redirect_helper(env : HTTP::Server::Context, locale : Hash(String, JSON::Any) | Nil)
request_path = env.request.path
if request_path.starts_with?("/search") || request_path.starts_with?("/watch") ||
request_path.starts_with?("/channel") || request_path.starts_with?("/playlist?list=PL")
next_steps_text = translate(locale, "next_steps_error_message")
refresh = translate(locale, "next_steps_error_message_refresh")
go_to_youtube = translate(locale, "next_steps_error_message_go_to_youtube")
switch_instance = translate(locale, "Switch Invidious Instance")
return <<-END_HTML
<p style="margin-bottom: 4px;">#{next_steps_text}</p>
<ul>
<li>
<a href="#{env.request.resource}">#{refresh}</a>
</li>
<li>
<a href="/redirect?referer=#{env.get("current_page")}">#{switch_instance}</a>
</li>
<li>
<a href="https://youtube.com#{env.request.resource}">#{go_to_youtube}</a>
</li>
</ul>
END_HTML
return next_step_html
else
return ""
end
end

View file

@ -4,4 +4,5 @@
<div class="h-box"> <div class="h-box">
<%= error_message %> <%= error_message %>
<%= next_steps %>
</div> </div>