mirror of
https://gitea.invidious.io/iv-org/invidious-copy-2022-03-16.git
synced 2024-08-15 00:53:18 +00:00
Make config a constant
Instead of passing around `config` there is now the global `CONFIG`.
This commit is contained in:
parent
f1a7ee997b
commit
b45f371911
14 changed files with 97 additions and 113 deletions
|
@ -1,9 +1,4 @@
|
|||
class Invidious::Jobs::BypassCaptchaJob < Invidious::Jobs::BaseJob
|
||||
private getter config : Config
|
||||
|
||||
def initialize(@config)
|
||||
end
|
||||
|
||||
def begin
|
||||
loop do
|
||||
begin
|
||||
|
@ -22,9 +17,9 @@ class Invidious::Jobs::BypassCaptchaJob < Invidious::Jobs::BaseJob
|
|||
|
||||
headers = response.cookies.add_request_headers(HTTP::Headers.new)
|
||||
|
||||
response = JSON.parse(HTTP::Client.post(config.captcha_api_url + "/createTask",
|
||||
response = JSON.parse(HTTP::Client.post(CONFIG.captcha_api_url + "/createTask",
|
||||
headers: HTTP::Headers{"Content-Type" => "application/json"}, body: {
|
||||
"clientKey" => config.captcha_key,
|
||||
"clientKey" => CONFIG.captcha_key,
|
||||
"task" => {
|
||||
"type" => "NoCaptchaTaskProxyless",
|
||||
"websiteURL" => "https://www.youtube.com#{path}",
|
||||
|
@ -39,9 +34,9 @@ class Invidious::Jobs::BypassCaptchaJob < Invidious::Jobs::BaseJob
|
|||
loop do
|
||||
sleep 10.seconds
|
||||
|
||||
response = JSON.parse(HTTP::Client.post(config.captcha_api_url + "/getTaskResult",
|
||||
response = JSON.parse(HTTP::Client.post(CONFIG.captcha_api_url + "/getTaskResult",
|
||||
headers: HTTP::Headers{"Content-Type" => "application/json"}, body: {
|
||||
"clientKey" => config.captcha_key,
|
||||
"clientKey" => CONFIG.captcha_key,
|
||||
"taskId" => task_id,
|
||||
}.to_json).body)
|
||||
|
||||
|
@ -58,10 +53,10 @@ class Invidious::Jobs::BypassCaptchaJob < Invidious::Jobs::BaseJob
|
|||
|
||||
response.cookies
|
||||
.select { |cookie| cookie.name != "PREF" }
|
||||
.each { |cookie| config.cookies << cookie }
|
||||
.each { |cookie| CONFIG.cookies << cookie }
|
||||
|
||||
# Persist cookies between runs
|
||||
File.write("config/config.yml", config.to_yaml)
|
||||
File.write("config/config.yml", CONFIG.to_yaml)
|
||||
elsif response.headers["Location"]?.try &.includes?("/sorry/index")
|
||||
location = response.headers["Location"].try { |u| URI.parse(u) }
|
||||
headers = HTTP::Headers{":authority" => location.host.not_nil!}
|
||||
|
@ -77,11 +72,11 @@ class Invidious::Jobs::BypassCaptchaJob < Invidious::Jobs::BaseJob
|
|||
inputs[node["name"]] = node["value"]
|
||||
end
|
||||
|
||||
captcha_client = HTTPClient.new(URI.parse(config.captcha_api_url))
|
||||
captcha_client.family = config.force_resolve || Socket::Family::INET
|
||||
captcha_client = HTTPClient.new(URI.parse(CONFIG.captcha_api_url))
|
||||
captcha_client.family = CONFIG.force_resolve || Socket::Family::INET
|
||||
response = JSON.parse(captcha_client.post("/createTask",
|
||||
headers: HTTP::Headers{"Content-Type" => "application/json"}, body: {
|
||||
"clientKey" => config.captcha_key,
|
||||
"clientKey" => CONFIG.captcha_key,
|
||||
"task" => {
|
||||
"type" => "NoCaptchaTaskProxyless",
|
||||
"websiteURL" => location.to_s,
|
||||
|
@ -100,7 +95,7 @@ class Invidious::Jobs::BypassCaptchaJob < Invidious::Jobs::BaseJob
|
|||
|
||||
response = JSON.parse(captcha_client.post("/getTaskResult",
|
||||
headers: HTTP::Headers{"Content-Type" => "application/json"}, body: {
|
||||
"clientKey" => config.captcha_key,
|
||||
"clientKey" => CONFIG.captcha_key,
|
||||
"taskId" => task_id,
|
||||
}.to_json).body)
|
||||
|
||||
|
@ -119,10 +114,10 @@ class Invidious::Jobs::BypassCaptchaJob < Invidious::Jobs::BaseJob
|
|||
}
|
||||
cookies = HTTP::Cookies.from_headers(headers)
|
||||
|
||||
cookies.each { |cookie| config.cookies << cookie }
|
||||
cookies.each { |cookie| CONFIG.cookies << cookie }
|
||||
|
||||
# Persist cookies between runs
|
||||
File.write("config/config.yml", config.to_yaml)
|
||||
File.write("config/config.yml", CONFIG.to_yaml)
|
||||
end
|
||||
end
|
||||
rescue ex
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
class Invidious::Jobs::RefreshChannelsJob < Invidious::Jobs::BaseJob
|
||||
private getter db : DB::Database
|
||||
private getter config : Config
|
||||
|
||||
def initialize(@db, @config)
|
||||
def initialize(@db)
|
||||
end
|
||||
|
||||
def begin
|
||||
max_fibers = config.channel_threads
|
||||
max_fibers = CONFIG.channel_threads
|
||||
lim_fibers = max_fibers
|
||||
active_fibers = 0
|
||||
active_channel = Channel(Bool).new
|
||||
|
@ -31,7 +30,7 @@ class Invidious::Jobs::RefreshChannelsJob < Invidious::Jobs::BaseJob
|
|||
spawn do
|
||||
begin
|
||||
LOGGER.trace("RefreshChannelsJob: #{id} fiber : Fetching channel")
|
||||
channel = fetch_channel(id, db, config.full_refresh)
|
||||
channel = fetch_channel(id, db, CONFIG.full_refresh)
|
||||
|
||||
lim_fibers = max_fibers
|
||||
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
class Invidious::Jobs::RefreshFeedsJob < Invidious::Jobs::BaseJob
|
||||
private getter db : DB::Database
|
||||
private getter config : Config
|
||||
|
||||
def initialize(@db, @config)
|
||||
def initialize(@db)
|
||||
end
|
||||
|
||||
def begin
|
||||
max_fibers = config.feed_threads
|
||||
max_fibers = CONFIG.feed_threads
|
||||
active_fibers = 0
|
||||
active_channel = Channel(Bool).new
|
||||
|
||||
|
|
|
@ -21,9 +21,8 @@ class Invidious::Jobs::StatisticsRefreshJob < Invidious::Jobs::BaseJob
|
|||
}
|
||||
|
||||
private getter db : DB::Database
|
||||
private getter config : Config
|
||||
|
||||
def initialize(@db, @config, @software_config : Hash(String, String))
|
||||
def initialize(@db, @software_config : Hash(String, String))
|
||||
end
|
||||
|
||||
def begin
|
||||
|
@ -43,7 +42,7 @@ class Invidious::Jobs::StatisticsRefreshJob < Invidious::Jobs::BaseJob
|
|||
"version" => @software_config["version"],
|
||||
"branch" => @software_config["branch"],
|
||||
}
|
||||
STATISTICS["openRegistration"] = config.registration_enabled
|
||||
STATISTICS["openRegistration"] = CONFIG.registration_enabled
|
||||
end
|
||||
|
||||
private def refresh_stats
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
class Invidious::Jobs::SubscribeToFeedsJob < Invidious::Jobs::BaseJob
|
||||
private getter db : DB::Database
|
||||
private getter hmac_key : String
|
||||
private getter config : Config
|
||||
|
||||
def initialize(@db, @config, @hmac_key)
|
||||
def initialize(@db, @hmac_key)
|
||||
end
|
||||
|
||||
def begin
|
||||
max_fibers = 1
|
||||
if config.use_pubsub_feeds.is_a?(Int32)
|
||||
max_fibers = config.use_pubsub_feeds.as(Int32)
|
||||
if CONFIG.use_pubsub_feeds.is_a?(Int32)
|
||||
max_fibers = CONFIG.use_pubsub_feeds.as(Int32)
|
||||
end
|
||||
|
||||
active_fibers = 0
|
||||
|
@ -30,7 +29,7 @@ class Invidious::Jobs::SubscribeToFeedsJob < Invidious::Jobs::BaseJob
|
|||
|
||||
spawn do
|
||||
begin
|
||||
response = subscribe_pubsub(ucid, hmac_key, config)
|
||||
response = subscribe_pubsub(ucid, hmac_key)
|
||||
|
||||
if response.status_code >= 400
|
||||
LOGGER.error("SubscribeToFeedsJob: #{ucid} : #{response.body}")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue