mirror of
https://github.com/iv-org/invidious.git
synced 2025-07-30 09:18:28 +00:00
Minor cleanup
This commit is contained in:
parent
969e40ed40
commit
a333bc6efe
@ -461,7 +461,6 @@
|
|||||||
"next_steps_error_message": "After which you should try to: ",
|
"next_steps_error_message": "After which you should try to: ",
|
||||||
"next_steps_error_message_refresh": "Refresh",
|
"next_steps_error_message_refresh": "Refresh",
|
||||||
"next_steps_error_message_go_to_youtube": "Go to YouTube",
|
"next_steps_error_message_go_to_youtube": "Go to YouTube",
|
||||||
"next_steps_error_message_open_embed_as_video": "Open in new page",
|
|
||||||
"footer_donate_page": "Donate",
|
"footer_donate_page": "Donate",
|
||||||
"footer_documentation": "Documentation",
|
"footer_documentation": "Documentation",
|
||||||
"footer_source_code": "Source code",
|
"footer_source_code": "Source code",
|
||||||
|
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
|
@ -1,4 +1,4 @@
|
|||||||
require "../spec_helper"
|
require "../env_helper"
|
||||||
require "kilt"
|
require "kilt"
|
||||||
|
|
||||||
Spectator.describe "error_redirect_helper" do
|
Spectator.describe "error_redirect_helper" do
|
||||||
|
@ -22,12 +22,3 @@ Spectator.configure do |config|
|
|||||||
config.fail_blank
|
config.fail_blank
|
||||||
config.randomize
|
config.randomize
|
||||||
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
|
|
||||||
|
@ -2,10 +2,6 @@
|
|||||||
# Issue template
|
# Issue template
|
||||||
# -------------------
|
# -------------------
|
||||||
|
|
||||||
class ContextWithPreferences < HTTP::Server::Context
|
|
||||||
property preferences : Preferences?
|
|
||||||
end
|
|
||||||
|
|
||||||
macro error_template(*args)
|
macro error_template(*args)
|
||||||
error_template_helper(env, {{args.splat}})
|
error_template_helper(env, {{args.splat}})
|
||||||
end
|
end
|
||||||
@ -172,10 +168,10 @@ end
|
|||||||
# Redirect
|
# Redirect
|
||||||
# -------------------
|
# -------------------
|
||||||
|
|
||||||
def error_redirect_helper(env : ContextWithPreferences)
|
def error_redirect_helper(env : HTTP::Server::Context)
|
||||||
request_path = env.request.path
|
request_path = env.request.path
|
||||||
|
|
||||||
locale = env.preferences.try &.locale
|
locale = env.get("preferences").as(Preferences).locale
|
||||||
|
|
||||||
display_on_path = %w[
|
display_on_path = %w[
|
||||||
/search
|
/search
|
||||||
@ -197,12 +193,5 @@ def error_redirect_helper(env : ContextWithPreferences)
|
|||||||
go_to_youtube => "https://youtube.com#{env.request.resource}"
|
go_to_youtube => "https://youtube.com#{env.request.resource}"
|
||||||
}
|
}
|
||||||
|
|
||||||
if request_path.starts_with?("/embed")
|
|
||||||
open_embed_as_video = translate(locale, "next_steps_error_message_open_embed_as_video")
|
|
||||||
|
|
||||||
non_embed_url = env.request.resource.sub("/embed/", "/watch?v=")
|
|
||||||
steps[open_embed_as_video] = non_embed_url
|
|
||||||
end
|
|
||||||
|
|
||||||
return rendered "components/error_redirect"
|
return rendered "components/error_redirect"
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user