Fix specs and clean up

This commit is contained in:
Joseph Johansen 2024-06-21 18:18:54 +01:00
parent a333bc6efe
commit 5b175f6b33
4 changed files with 20 additions and 22 deletions

View File

@ -8,7 +8,7 @@ Spectator.describe "error_redirect_helper" do
test_env.set "current_page", current_url
html = error_redirect_helper(test_env)
expect(html).to eq "<p style=\"margin-bottom: 4px;\">After which you should try to: </p>\n<ul>\n \n <li>\n <a href=\"/embed/IeQT18gaB-c?si=YxBQzH-GBSTS4vBS\">Refresh</a>\n </li>\n \n <li>\n <a href=\"/redirect?referer=/embed/IeQT18gaB-c?si=YxBQzH-GBSTS4vBS\">Switch Invidious Instance</a>\n </li>\n \n <li>\n <a href=\"https://youtube.com/embed/IeQT18gaB-c?si=YxBQzH-GBSTS4vBS\">Go to YouTube</a>\n </li>\n \n <li>\n <a href=\"/watch?v=IeQT18gaB-c?si=YxBQzH-GBSTS4vBS\">Open in new page</a>\n </li>\n \n</ul>\n"
expect(html).to eq "<p style=\"margin-bottom: 4px;\">After which you should try to: </p>\n<ul>\n \n <li>\n <a href=\"/embed/IeQT18gaB-c?si=YxBQzH-GBSTS4vBS\">Refresh</a>\n </li>\n \n <li>\n <a href=\"/redirect?referer=/embed/IeQT18gaB-c?si=YxBQzH-GBSTS4vBS\">Switch Invidious Instance</a>\n </li>\n \n <li>\n <a href=\"https://youtube.com/embed/IeQT18gaB-c?si=YxBQzH-GBSTS4vBS\">Go to YouTube</a>\n </li>\n \n</ul>\n"
end
it "shows next steps for watch pages" do

View File

@ -12,6 +12,8 @@ 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"))

View File

@ -80,7 +80,7 @@ class Config
property full_refresh : Bool = false
# Jobs config structure. See jobs.cr and jobs/base_job.cr
# property jobs = Invidious::Jobs::JobsConfig.new
property jobs = Invidious::Jobs::JobsConfig.new
# Used to tell Invidious it is behind a proxy, so links to resources should be https://
property https_only : Bool?

View File

@ -173,25 +173,21 @@ def error_redirect_helper(env : HTTP::Server::Context)
locale = env.get("preferences").as(Preferences).locale
display_on_path = %w[
/search
/channel
/watch
/playlist?list=PL
/embed
]
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?("/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 "" if display_on_path.none? { |path| request_path.starts_with? path }
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 rendered "components/error_redirect"
return rendered "components/error_redirect"
else
return ""
end
end