Update pubsub to support lease_seconds

This commit is contained in:
Omar Roth 2019-03-03 20:40:24 -06:00
parent 8e884fe115
commit 7425700009
5 changed files with 19 additions and 13 deletions

View file

@ -4,7 +4,7 @@ class InvidiousChannel
author: String,
updated: Time,
deleted: Bool,
subscribed: {type: Bool, default: false},
subscribed: Time?,
})
end
@ -186,7 +186,7 @@ def fetch_channel(ucid, db, pull_all_videos = true, locale = nil)
db.exec("DELETE FROM channel_videos * WHERE NOT id = ANY ('{#{ids.map { |id| %("#{id}") }.join(",")}}') AND ucid = $1", ucid)
end
channel = InvidiousChannel.new(ucid, author, Time.now, false, false)
channel = InvidiousChannel.new(ucid, author, Time.now, false, nil)
return channel
end
@ -198,12 +198,12 @@ def subscribe_pubsub(ucid, key, config)
host_url = make_host_url(Kemal.config.ssl || config.https_only, config.domain)
body = {
"hub.callback" => "#{host_url}/feed/webhook",
"hub.topic" => "https://www.youtube.com/feeds/videos.xml?channel_id=#{ucid}",
"hub.verify" => "async",
"hub.mode" => "subscribe",
"hub.verify_token" => "#{time}:#{OpenSSL::HMAC.hexdigest(:sha1, key, time)}",
"hub.secret" => key.to_s,
"hub.callback" => "#{host_url}/feed/webhook/#{time}:#{OpenSSL::HMAC.hexdigest(:sha1, key, time)}",
"hub.topic" => "https://www.youtube.com/feeds/videos.xml?channel_id=#{ucid}",
"hub.verify" => "async",
"hub.mode" => "subscribe",
"hub.lease_seconds" => "432000",
"hub.secret" => key.to_s,
}
return client.post("/subscribe", form: body)

View file

@ -157,7 +157,7 @@ def subscribe_to_feeds(db, logger, key, config)
if config.use_pubsub_feeds
spawn do
loop do
db.query_all("SELECT id FROM channels WHERE subscribed = false") do |rs|
db.query_all("SELECT id FROM channels WHERE CURRENT_TIMESTAMP - subscribed > '4 days'") do |rs|
ucid = rs.read(String)
response = subscribe_pubsub(ucid, key, config)