diff --git a/spec/env_helper.cr b/spec/env_helper.cr
new file mode 100644
index 00000000..6cfb84eb
--- /dev/null
+++ b/spec/env_helper.cr
@@ -0,0 +1,34 @@
+require "./spec_helper"
+
+class ContextWithPreferences < HTTP::Server::Context
+ property preferences : Preferences?
+
+ def get(key : String)
+ return preferences if key == "preferences"
+
+ super
+ end
+
+ def get?(key : String)
+ return preferences if key == "preferences"
+
+ super
+ end
+
+ def set(key : String, val : Preferences)
+ if key == "preferences"
+ self.preferences = val
+ else
+ super
+ end
+ end
+end
+
+def test_env(current_url : String, request_method : String = "GET", response : IO = String::Builder.new)
+ con = ContextWithPreferences.new(
+ HTTP::Request.new(request_method, current_url),
+ HTTP::Server::Response.new(response),
+ )
+ con.preferences = Preferences.new(CONFIG.default_user_preferences.to_tuple)
+ con
+end
diff --git a/spec/helpers/errors_spec.cr b/spec/helpers/errors_spec.cr
new file mode 100644
index 00000000..a07e2f2e
--- /dev/null
+++ b/spec/helpers/errors_spec.cr
@@ -0,0 +1,31 @@
+require "../env_helper"
+require "kilt"
+
+Spectator.describe "error_redirect_helper" do
+ it "shows next steps on embed page errors" do
+ current_url = "/embed/IeQT18gaB-c?si=YxBQzH-GBSTS4vBS"
+ test_env = test_env current_url
+ test_env.set "current_page", current_url
+
+ html = error_redirect_helper(test_env)
+ expect(html).to eq "
After which you should try to:
\n\n"
+ end
+
+ it "shows next steps for watch pages" do
+ current_url = "/watch?v=IeQT18gaB-c?si=YxBQzH-GBSTS4vBS"
+ test_env = test_env current_url
+ test_env.set "current_page", current_url
+
+ html = error_redirect_helper(test_env)
+ expect(html).to eq "After which you should try to:
\n\n"
+ end
+
+ it "returns an empty string for unknown pages" do
+ current_url = "/foo"
+ test_env = test_env current_url
+ test_env.set "current_page", current_url
+
+ html = error_redirect_helper(test_env)
+ expect(html).to eq ""
+ end
+end
diff --git a/spec/invidious/helpers_spec.cr b/spec/invidious/helpers_spec.cr
index 9fbb6d6f..35387f09 100644
--- a/spec/invidious/helpers_spec.cr
+++ b/spec/invidious/helpers_spec.cr
@@ -1,7 +1,5 @@
require "../spec_helper"
-CONFIG = Config.from_yaml(File.open("config/config.example.yml"))
-
Spectator.describe "Helper" do
describe "#produce_channel_search_continuation" do
it "correctly produces token for searching a specific channel" do
diff --git a/spec/spec_helper.cr b/spec/spec_helper.cr
index b3060acf..035196b8 100644
--- a/spec/spec_helper.cr
+++ b/spec/spec_helper.cr
@@ -10,8 +10,14 @@ require "../src/invidious/videos"
require "../src/invidious/playlists"
require "../src/invidious/search/ctoken"
require "../src/invidious/trending"
+require "../src/invidious/config"
+require "../src/invidious/user/preferences.cr"
+require "../src/invidious/jobs"
+require "../src/invidious/jobs/*"
require "spectator"
+CONFIG = Config.from_yaml(File.open("config/config.example.yml"))
+
Spectator.configure do |config|
config.fail_blank
config.randomize
diff --git a/src/invidious/helpers/errors.cr b/src/invidious/helpers/errors.cr
index 21b789bc..514a425a 100644
--- a/src/invidious/helpers/errors.cr
+++ b/src/invidious/helpers/errors.cr
@@ -174,26 +174,19 @@ def error_redirect_helper(env : HTTP::Server::Context)
locale = env.get("preferences").as(Preferences).locale
if request_path.starts_with?("/search") || request_path.starts_with?("/watch") ||
- request_path.starts_with?("/channel") || request_path.starts_with?("/playlist?list=PL")
+ request_path.starts_with?("/channel") || request_path.starts_with?("/playlist?list=PL") ||
+ request_path.starts_with?("/embed")
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")
+ steps = {
+ refresh => env.request.resource,
+ switch_instance => "/redirect?referer=#{env.get("current_page")}",
+ go_to_youtube => "https://youtube.com#{env.request.resource}"
+ }
- return <<-END_HTML
- #{next_steps_text}
-
- END_HTML
+ return rendered "components/error_redirect"
else
return ""
end
diff --git a/src/invidious/views/components/error_redirect.ecr b/src/invidious/views/components/error_redirect.ecr
new file mode 100644
index 00000000..a648f5e7
--- /dev/null
+++ b/src/invidious/views/components/error_redirect.ecr
@@ -0,0 +1,8 @@
+<%= next_steps_text %>
+
+ <% steps.each do |label, href| %>
+ -
+ <%= label %>
+
+ <% end %>
+