mirror of
https://github.com/iv-org/invidious.git
synced 2025-04-19 15:15:58 -04:00
Merge f52ef639eda266ffcd4527a8053941d17cd5d3e6 into 90e94d4e6cc126a8b7a091d12d7a5556bfe369d5
This commit is contained in:
commit
8078d07faf
34
spec/env_helper.cr
Normal file
34
spec/env_helper.cr
Normal file
@ -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
|
31
spec/helpers/errors_spec.cr
Normal file
31
spec/helpers/errors_spec.cr
Normal file
@ -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 "<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
|
||||
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 "<p style=\"margin-bottom: 4px;\">After which you should try to: </p>\n<ul>\n \n <li>\n <a href=\"/watch?v=IeQT18gaB-c?si=YxBQzH-GBSTS4vBS\">Refresh</a>\n </li>\n \n <li>\n <a href=\"/redirect?referer=/watch?v=IeQT18gaB-c?si=YxBQzH-GBSTS4vBS\">Switch Invidious Instance</a>\n </li>\n \n <li>\n <a href=\"https://youtube.com/watch?v=IeQT18gaB-c?si=YxBQzH-GBSTS4vBS\">Go to YouTube</a>\n </li>\n \n</ul>\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
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
<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 rendered "components/error_redirect"
|
||||
else
|
||||
return ""
|
||||
end
|
||||
|
8
src/invidious/views/components/error_redirect.ecr
Normal file
8
src/invidious/views/components/error_redirect.ecr
Normal file
@ -0,0 +1,8 @@
|
||||
<p style="margin-bottom: 4px;"><%= next_steps_text %></p>
|
||||
<ul>
|
||||
<% steps.each do |label, href| %>
|
||||
<li>
|
||||
<a href="<%= href %>"><%= label %></a>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
Loading…
x
Reference in New Issue
Block a user