generate CSP each time the backend checker runs instead of each request made to invidious

This commit is contained in:
Fijxu 2025-03-31 00:03:40 -03:00
parent d47aa3dd6a
commit 895745934b
Signed by: Fijxu
GPG key ID: 32C1DDF333EDA6A4
2 changed files with 26 additions and 12 deletions

View file

@ -2,12 +2,15 @@ module BackendInfo
extend self
@@exvpp_url : Array(String) = Array.new(CONFIG.invidious_companion.size, "")
@@status : Array(Int32) = Array.new(CONFIG.invidious_companion.size, 0)
@@extra_media_csp : String = ""
@@extra_connect_csp : String = ""
def check_backends
check_companion()
generate_csp()
end
def check_companion
private def check_companion
CONFIG.invidious_companion.each_with_index do |companion, index|
spawn do
begin
@ -50,6 +53,23 @@ module BackendInfo
end
end
private def generate_csp
@@extra_media_csp = ""
@@extra_connect_csp = ""
CONFIG.invidious_companion.each do |companion|
@@extra_media_csp += " #{companion.public_url}"
@@extra_connect_csp += " #{companion.public_url}"
end
exvpp_urls = self.get_exvpp
exvpp_urls.each do |exvpp_url|
if !exvpp_url.empty?
@@extra_media_csp += " #{exvpp_url}"
@@extra_connect_csp += " #{exvpp_url}"
end
end
end
def get_status
return @@status
end
@ -57,4 +77,8 @@ module BackendInfo
def get_exvpp
return @@exvpp_url
end
def get_csp
return @@extra_media_csp, @@extra_connect_csp
end
end

View file

@ -41,17 +41,7 @@ module Invidious::Routes::BeforeAll
env.set "current_companion", current_companion
CONFIG.invidious_companion.each do |companion|
extra_media_csp += " #{companion.public_url}"
extra_connect_csp += " #{companion.public_url}"
end
exvpp_urls = BackendInfo.get_exvpp
exvpp_urls.each do |exvpp_url|
if !exvpp_url.empty?
extra_media_csp += " #{exvpp_url}"
extra_connect_csp += " #{exvpp_url}"
end
end
extra_media_csp, extra_connect_csp = BackendInfo.get_csp()
end
if !CONFIG.external_videoplayback_proxy.empty?