tokens: rename Tokens to SessionTokens

This commit is contained in:
Fijxu 2024-12-14 17:17:27 -03:00
parent 58c4d8c951
commit a01c8c63d3
Signed by: Fijxu
GPG key ID: 32C1DDF333EDA6A4
3 changed files with 12 additions and 12 deletions

View file

@ -214,9 +214,9 @@ if !CONFIG.external_videoplayback_proxy.empty?
end end
if !CONFIG.tokens_server.empty? if !CONFIG.tokens_server.empty?
Invidious::Jobs.register Invidious::Jobs::RefreshTokens.new Invidious::Jobs.register Invidious::Jobs::RefreshSessionTokens.new
else 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 end
Invidious::Jobs.start_all Invidious::Jobs.start_all

View file

@ -1,4 +1,4 @@
module Tokens module SessionTokens
extend self extend self
@@po_token : String | Nil @@po_token : String | Nil
@@visitor_data : String | Nil @@visitor_data : String | Nil
@ -7,25 +7,25 @@ module Tokens
begin begin
response = HTTP::Client.get "#{CONFIG.tokens_server}/generate" response = HTTP::Client.get "#{CONFIG.tokens_server}/generate"
if !response.status_code == 200 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 end
json = JSON.parse(response.body) json = JSON.parse(response.body)
@@po_token = json.try &.["potoken"].as_s || nil @@po_token = json.try &.["potoken"].as_s || nil
@@visitor_data = json.try &.["visitorData"].as_s || nil @@visitor_data = json.try &.["visitorData"].as_s || nil
rescue ex 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 return
end end
if !@@po_token.nil? && !@@visitor_data.nil? if !@@po_token.nil? && !@@visitor_data.nil?
set_tokens set_tokens
LOGGER.debug("RefreshTokens: Successfully updated po_token and visitor_data") LOGGER.debug("RefreshSessionTokens: Successfully updated po_token and visitor_data")
else 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 end
LOGGER.trace("RefreshTokens: Tokens are:") LOGGER.trace("RefreshSessionTokens: Tokens are:")
LOGGER.trace("RefreshTokens: po_token: #{CONFIG.po_token}") LOGGER.trace("RefreshSessionTokens: po_token: #{CONFIG.po_token}")
LOGGER.trace("RefreshTokens: visitor_data: #{CONFIG.visitor_data}") LOGGER.trace("RefreshSessionTokens: visitor_data: #{CONFIG.visitor_data}")
end end
def set_tokens def set_tokens

View file

@ -1,10 +1,10 @@
class Invidious::Jobs::RefreshTokens < Invidious::Jobs::BaseJob class Invidious::Jobs::RefreshSessionTokens < Invidious::Jobs::BaseJob
def initialize def initialize
end end
def begin def begin
loop do loop do
Tokens.refresh_tokens SessionTokens.refresh_tokens
LOGGER.info("RefreshTokens: Done, sleeping for 5 seconds") LOGGER.info("RefreshTokens: Done, sleeping for 5 seconds")
sleep 5.seconds sleep 5.seconds
Fiber.yield Fiber.yield