tokens: rename Tokens to SessionTokens
This commit is contained in:
parent
58c4d8c951
commit
a01c8c63d3
3 changed files with 12 additions and 12 deletions
|
@ -214,9 +214,9 @@ if !CONFIG.external_videoplayback_proxy.empty?
|
|||
end
|
||||
|
||||
if !CONFIG.tokens_server.empty?
|
||||
Invidious::Jobs.register Invidious::Jobs::RefreshTokens.new
|
||||
Invidious::Jobs.register Invidious::Jobs::RefreshSessionTokens.new
|
||||
else
|
||||
LOGGER.info("jobs: Disabling RefreshTokens job. Invidious will use the tokens that are on the configuration file")
|
||||
LOGGER.info("jobs: Disabling RefreshSessionTokens job. Invidious will use the tokens that are on the configuration file")
|
||||
end
|
||||
|
||||
Invidious::Jobs.start_all
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
module Tokens
|
||||
module SessionTokens
|
||||
extend self
|
||||
@@po_token : String | Nil
|
||||
@@visitor_data : String | Nil
|
||||
|
@ -7,25 +7,25 @@ module Tokens
|
|||
begin
|
||||
response = HTTP::Client.get "#{CONFIG.tokens_server}/generate"
|
||||
if !response.status_code == 200
|
||||
LOGGER.error("RefreshTokens: Expected response to have status code 200 but got #{response.status_code} from #{CONFIG.tokens_server}")
|
||||
LOGGER.error("RefreshSessionTokens: Expected response to have status code 200 but got #{response.status_code} from #{CONFIG.tokens_server}")
|
||||
end
|
||||
json = JSON.parse(response.body)
|
||||
@@po_token = json.try &.["potoken"].as_s || nil
|
||||
@@visitor_data = json.try &.["visitorData"].as_s || nil
|
||||
rescue ex
|
||||
LOGGER.error("RefreshTokens: Failed to fetch tokens from #{CONFIG.tokens_server}: #{ex.message}")
|
||||
LOGGER.error("RefreshSessionTokens: Failed to fetch tokens from #{CONFIG.tokens_server}: #{ex.message}")
|
||||
return
|
||||
end
|
||||
|
||||
if !@@po_token.nil? && !@@visitor_data.nil?
|
||||
set_tokens
|
||||
LOGGER.debug("RefreshTokens: Successfully updated po_token and visitor_data")
|
||||
LOGGER.debug("RefreshSessionTokens: Successfully updated po_token and visitor_data")
|
||||
else
|
||||
LOGGER.warn("RefreshTokens: Tokens are empty!. Invidious will use the tokens that are on the configuration file")
|
||||
LOGGER.warn("RefreshSessionTokens: Tokens are empty!. Invidious will use the tokens that are on the configuration file")
|
||||
end
|
||||
LOGGER.trace("RefreshTokens: Tokens are:")
|
||||
LOGGER.trace("RefreshTokens: po_token: #{CONFIG.po_token}")
|
||||
LOGGER.trace("RefreshTokens: visitor_data: #{CONFIG.visitor_data}")
|
||||
LOGGER.trace("RefreshSessionTokens: Tokens are:")
|
||||
LOGGER.trace("RefreshSessionTokens: po_token: #{CONFIG.po_token}")
|
||||
LOGGER.trace("RefreshSessionTokens: visitor_data: #{CONFIG.visitor_data}")
|
||||
end
|
||||
|
||||
def set_tokens
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
class Invidious::Jobs::RefreshTokens < Invidious::Jobs::BaseJob
|
||||
class Invidious::Jobs::RefreshSessionTokens < Invidious::Jobs::BaseJob
|
||||
def initialize
|
||||
end
|
||||
|
||||
def begin
|
||||
loop do
|
||||
Tokens.refresh_tokens
|
||||
SessionTokens.refresh_tokens
|
||||
LOGGER.info("RefreshTokens: Done, sleeping for 5 seconds")
|
||||
sleep 5.seconds
|
||||
Fiber.yield
|
||||
|
|
Loading…
Reference in a new issue