-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Show available actions on embed error page #4760
Open
johansenja
wants to merge
4
commits into
iv-org:master
Choose a base branch
from
johansenja:show-actions-embed-error-page
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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}" | ||||||||||||||||||||||
} | ||||||||||||||||||||||
Comment on lines
+183
to
+187
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that by doing that, you're creating a
Suggested change
|
||||||||||||||||||||||
|
||||||||||||||||||||||
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 | ||||||||||||||||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a second I though that we had an URL handling issue, but it's just that you're not passing an encoded URL like the HTTP server handlers would do (see how in the "Switch Invidious Instance" URL nothing after
referer=
is URL encoded?).It also made me realize that the
si=
parameter isn't removed from the "Watch on Youtube URL" (for the record, this is used to track who shared the video)