From 5b175f6b33435b35e0048428f2855eaa3fa09f66 Mon Sep 17 00:00:00 2001 From: Joseph Johansen Date: Fri, 21 Jun 2024 18:18:54 +0100 Subject: [PATCH] Fix specs and clean up --- spec/helpers/errors_spec.cr | 2 +- spec/spec_helper.cr | 2 ++ src/invidious/config.cr | 2 +- src/invidious/helpers/errors.cr | 36 +++++++++++++++------------------ 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/spec/helpers/errors_spec.cr b/spec/helpers/errors_spec.cr index 4deacbd1..a07e2f2e 100644 --- a/spec/helpers/errors_spec.cr +++ b/spec/helpers/errors_spec.cr @@ -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 "

After which you should try to:

\n\n" + expect(html).to eq "

After which you should try to:

\n\n" end it "shows next steps for watch pages" do diff --git a/spec/spec_helper.cr b/spec/spec_helper.cr index 4b4f04ef..16bf421c 100644 --- a/spec/spec_helper.cr +++ b/spec/spec_helper.cr @@ -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")) diff --git a/src/invidious/config.cr b/src/invidious/config.cr index a13fe873..09c2168b 100644 --- a/src/invidious/config.cr +++ b/src/invidious/config.cr @@ -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? diff --git a/src/invidious/helpers/errors.cr b/src/invidious/helpers/errors.cr index 0651a954..514a425a 100644 --- a/src/invidious/helpers/errors.cr +++ b/src/invidious/helpers/errors.cr @@ -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