mirror of
https://github.com/iv-org/invidious.git
synced 2025-08-07 13:18:30 +00:00
Moved notification logic into its own job
This commit is contained in:
parent
cbcc790797
commit
f328cad192
@ -162,17 +162,20 @@ end
|
||||
Invidious::Jobs.register Invidious::Jobs::RefreshChannelsJob.new(PG_DB, logger, config)
|
||||
Invidious::Jobs.register Invidious::Jobs::RefreshFeedsJob.new(PG_DB, logger, config)
|
||||
Invidious::Jobs.register Invidious::Jobs::SubscribeToFeedsJob.new(PG_DB, logger, config, HMAC_KEY)
|
||||
Invidious::Jobs.register Invidious::Jobs::PullPopularVideosJob.new(PG_DB)
|
||||
Invidious::Jobs.register Invidious::Jobs::UpdateDecryptFunctionJob.new
|
||||
|
||||
if config.statistics_enabled
|
||||
Invidious::Jobs.register Invidious::Jobs::StatisticsRefreshJob.new(PG_DB, config, SOFTWARE)
|
||||
end
|
||||
|
||||
if CONFIG.captcha_key
|
||||
if config.captcha_key
|
||||
Invidious::Jobs.register Invidious::Jobs::BypassCaptchaJob.new(logger, config)
|
||||
end
|
||||
|
||||
Invidious::Jobs.register Invidious::Jobs::PullPopularVideosJob.new(PG_DB)
|
||||
Invidious::Jobs.register Invidious::Jobs::UpdateDecryptFunctionJob.new
|
||||
connection_channel = Channel({Bool, Channel(PQ::Notification)}).new(32)
|
||||
Invidious::Jobs.register Invidious::Jobs::NotificationJob.new(connection_channel, PG_URL)
|
||||
|
||||
Invidious::Jobs.start_all
|
||||
|
||||
def popular_videos
|
||||
@ -181,24 +184,6 @@ end
|
||||
|
||||
DECRYPT_FUNCTION = Invidious::Jobs::UpdateDecryptFunctionJob::DECRYPT_FUNCTION
|
||||
|
||||
connection_channel = Channel({Bool, Channel(PQ::Notification)}).new(32)
|
||||
spawn do
|
||||
connections = [] of Channel(PQ::Notification)
|
||||
|
||||
PG.connect_listen(PG_URL, "notifications") { |event| connections.each { |connection| connection.send(event) } }
|
||||
|
||||
loop do
|
||||
action, connection = connection_channel.receive
|
||||
|
||||
case action
|
||||
when true
|
||||
connections << connection
|
||||
when false
|
||||
connections.delete(connection)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
before_all do |env|
|
||||
preferences = begin
|
||||
Preferences.from_json(env.request.cookies["PREFS"]?.try &.value || "{}")
|
||||
|
@ -56,11 +56,10 @@ class Invidious::Jobs::BypassCaptchaJob < Invidious::Jobs::BaseJob
|
||||
response = YT_POOL.client &.post("/das_captcha", headers, form: inputs)
|
||||
|
||||
response.cookies
|
||||
.select { |cookie| cookie.name != "PREF" }
|
||||
.each { |cookie| config.cookies << cookie }
|
||||
.select { |cookie| cookie.name != "PREF" }
|
||||
.each { |cookie| config.cookies << cookie }
|
||||
|
||||
# Persist cookies between runs
|
||||
config.cookies = config.cookies
|
||||
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) }
|
||||
@ -118,7 +117,6 @@ class Invidious::Jobs::BypassCaptchaJob < Invidious::Jobs::BaseJob
|
||||
cookies.each { |cookie| config.cookies << cookie }
|
||||
|
||||
# Persist cookies between runs
|
||||
config.cookies = config.cookies
|
||||
File.write("config/config.yml", config.to_yaml)
|
||||
end
|
||||
end
|
||||
|
24
src/invidious/jobs/notification_job.cr
Normal file
24
src/invidious/jobs/notification_job.cr
Normal file
@ -0,0 +1,24 @@
|
||||
class Invidious::Jobs::NotificationJob < Invidious::Jobs::BaseJob
|
||||
private getter connection_channel : Channel({Bool, Channel(PQ::Notification)})
|
||||
private getter pg_url : URI
|
||||
|
||||
def initialize(@connection_channel, @pg_url)
|
||||
end
|
||||
|
||||
def begin
|
||||
connections = [] of Channel(PQ::Notification)
|
||||
|
||||
PG.connect_listen(pg_url, "notifications") { |event| connections.each(&.send(event)) }
|
||||
|
||||
loop do
|
||||
action, connection = connection_channel.receive
|
||||
|
||||
case action
|
||||
when true
|
||||
connections << connection
|
||||
when false
|
||||
connections.delete(connection)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user