From b9cd40fe1e095f72440bb64180314b71d4f3f185 Mon Sep 17 00:00:00 2001 From: syeopite Date: Sat, 15 May 2021 22:01:46 -0700 Subject: [PATCH] Add redirect buttons to error template --- locales/en-US.json | 5 ++++- src/invidious/helpers/errors.cr | 37 +++++++++++++++++++++++++++++++++ src/invidious/views/error.ecr | 1 + 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/locales/en-US.json b/locales/en-US.json index 29eae79e..106bdcf2 100644 --- a/locales/en-US.json +++ b/locales/en-US.json @@ -419,5 +419,8 @@ "location": "Location", "hdr": "HDR", "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" } diff --git a/src/invidious/helpers/errors.cr b/src/invidious/helpers/errors.cr index 68ced430..714e0670 100644 --- a/src/invidious/helpers/errors.cr +++ b/src/invidious/helpers/errors.cr @@ -40,6 +40,9 @@ def error_template_helper(env : HTTP::Server::Context, locale : Hash(String, JSO and include the following text in your message:
#{issue_template}
END_HTML + + next_steps = error_redirect_helper(env, locale) + return templated "error" 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.status_code = status_code error_message = translate(locale, message) + next_steps = error_redirect_helper(env, locale) return templated "error" 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) error_json_helper(env, locale, status_code, message, nil) 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 +

#{next_steps_text}

+ + END_HTML + + return next_step_html + else + return "" + end +end \ No newline at end of file diff --git a/src/invidious/views/error.ecr b/src/invidious/views/error.ecr index d0752e5b..04eb74d5 100644 --- a/src/invidious/views/error.ecr +++ b/src/invidious/views/error.ecr @@ -4,4 +4,5 @@
<%= error_message %> + <%= next_steps %>