External Proxies: Use list of external videoplayback proxies
All checks were successful
Invidious CI / build (push) Successful in 5m14s
All checks were successful
Invidious CI / build (push) Successful in 5m14s
This commit is contained in:
parent
b551fcf96a
commit
e78f7e5430
5 changed files with 34 additions and 17 deletions
|
@ -72,6 +72,7 @@ PUBSUB_URL = URI.parse("https://pubsubhubbub.appspot.com")
|
||||||
REDDIT_URL = URI.parse("https://www.reddit.com")
|
REDDIT_URL = URI.parse("https://www.reddit.com")
|
||||||
YT_URL = URI.parse("https://www.youtube.com")
|
YT_URL = URI.parse("https://www.youtube.com")
|
||||||
HOST_URL = make_host_url(Kemal.config)
|
HOST_URL = make_host_url(Kemal.config)
|
||||||
|
EXT_VIDEOP_LIST = gen_videoplayback_proxy_list()
|
||||||
|
|
||||||
CHARS_SAFE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
|
CHARS_SAFE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
|
||||||
TEST_IDS = {"AgbeGFYluEA", "BaW_jenozKc", "a9LDPn-MO4I", "ddFvjfvPnqk", "iqKdEhx-dD4"}
|
TEST_IDS = {"AgbeGFYluEA", "BaW_jenozKc", "a9LDPn-MO4I", "ddFvjfvPnqk", "iqKdEhx-dD4"}
|
||||||
|
@ -188,7 +189,7 @@ Invidious::Jobs.register Invidious::Jobs::ClearExpiredItemsJob.new
|
||||||
|
|
||||||
Invidious::Jobs.register Invidious::Jobs::InstanceListRefreshJob.new
|
Invidious::Jobs.register Invidious::Jobs::InstanceListRefreshJob.new
|
||||||
|
|
||||||
if CONFIG.external_videoplayback_proxy
|
if !CONFIG.external_videoplayback_proxy.empty?
|
||||||
Invidious::Jobs.register Invidious::Jobs::CheckExternalProxy.new
|
Invidious::Jobs.register Invidious::Jobs::CheckExternalProxy.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -180,7 +180,9 @@ class Config
|
||||||
# of the backend
|
# of the backend
|
||||||
property backends_delimiter : String = "|"
|
property backends_delimiter : String = "|"
|
||||||
|
|
||||||
property external_videoplayback_proxy : String?
|
# External videoplayback proxies list. They should include `https://`
|
||||||
|
# at the start of the URI
|
||||||
|
property external_videoplayback_proxy : Array(String) = [] of String
|
||||||
|
|
||||||
# Materialious redirects
|
# Materialious redirects
|
||||||
property materialious_domain : String?
|
property materialious_domain : String?
|
||||||
|
|
|
@ -383,3 +383,17 @@ def parse_link_endpoint(endpoint : JSON::Any, text : String, video_id : String)
|
||||||
end
|
end
|
||||||
return text
|
return text
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Generates a list of external videoplayback proxies for
|
||||||
|
# CSP
|
||||||
|
def gen_videoplayback_proxy_list
|
||||||
|
if !CONFIG.external_videoplayback_proxy.empty?
|
||||||
|
external_videoplayback_proxy = ""
|
||||||
|
CONFIG.external_videoplayback_proxy.each do |proxy|
|
||||||
|
external_videoplayback_proxy += " #{proxy}"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
external_videoplayback_proxy = ""
|
||||||
|
end
|
||||||
|
return external_videoplayback_proxy
|
||||||
|
end
|
||||||
|
|
|
@ -4,14 +4,20 @@ module Invidious::HttpServer
|
||||||
module Utils
|
module Utils
|
||||||
extend self
|
extend self
|
||||||
|
|
||||||
@@proxy_alive : Bool = false
|
@@proxy_alive : String = ""
|
||||||
|
|
||||||
def check_external_proxy
|
def check_external_proxy
|
||||||
begin
|
CONFIG.external_videoplayback_proxy.each do |proxy|
|
||||||
response = HTTP::Client.get("#{CONFIG.external_videoplayback_proxy}")
|
begin
|
||||||
@@proxy_alive = response.status_code == 200
|
response = HTTP::Client.get(proxy)
|
||||||
rescue
|
if response.status_code == 200
|
||||||
@@proxy_alive = false
|
@@proxy_alive = proxy
|
||||||
|
LOGGER.debug("CheckExternalProxy: Proxy set to: '#{proxy}'")
|
||||||
|
break
|
||||||
|
end
|
||||||
|
rescue
|
||||||
|
LOGGER.debug("CheckExternalProxy: Proxy '#{proxy}' is not available")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -25,8 +31,8 @@ module Invidious::HttpServer
|
||||||
url.query_params = params
|
url.query_params = params
|
||||||
|
|
||||||
if absolute
|
if absolute
|
||||||
if @@proxy_alive
|
if !@@proxy_alive.empty?
|
||||||
return "#{CONFIG.external_videoplayback_proxy}#{url.request_target}"
|
return "#{@@proxy_alive}#{url.request_target}"
|
||||||
else
|
else
|
||||||
return "#{HOST_URL}#{url.request_target}"
|
return "#{HOST_URL}#{url.request_target}"
|
||||||
end
|
end
|
||||||
|
|
|
@ -28,12 +28,6 @@ module Invidious::Routes::BeforeAll
|
||||||
extra_media_csp = ""
|
extra_media_csp = ""
|
||||||
end
|
end
|
||||||
|
|
||||||
if CONFIG.external_videoplayback_proxy
|
|
||||||
external_videoplayback_proxy = " #{CONFIG.external_videoplayback_proxy}"
|
|
||||||
else
|
|
||||||
external_videoplayback_proxy = ""
|
|
||||||
end
|
|
||||||
|
|
||||||
# Only allow the pages at /embed/* to be embedded
|
# Only allow the pages at /embed/* to be embedded
|
||||||
if env.request.resource.starts_with?("/embed")
|
if env.request.resource.starts_with?("/embed")
|
||||||
frame_ancestors = "'self' file: http: https:"
|
frame_ancestors = "'self' file: http: https:"
|
||||||
|
@ -49,7 +43,7 @@ module Invidious::Routes::BeforeAll
|
||||||
"style-src 'self' 'unsafe-inline'",
|
"style-src 'self' 'unsafe-inline'",
|
||||||
"img-src 'self' data:",
|
"img-src 'self' data:",
|
||||||
"font-src 'self' data:",
|
"font-src 'self' data:",
|
||||||
"connect-src 'self'" + external_videoplayback_proxy,
|
"connect-src 'self'" + EXT_VIDEOP_LIST,
|
||||||
"manifest-src 'self'",
|
"manifest-src 'self'",
|
||||||
"media-src 'self' blob:" + extra_media_csp,
|
"media-src 'self' blob:" + extra_media_csp,
|
||||||
"child-src 'self' blob:",
|
"child-src 'self' blob:",
|
||||||
|
|
Loading…
Reference in a new issue