SigHelper: Make signature server optional and configurable

This commit is contained in:
Samantaz Fox
2024-08-07 23:12:27 +02:00
parent ec1bb5db87
commit 7798faf234
6 changed files with 39 additions and 27 deletions

View File

@@ -1,10 +1,11 @@
require "http/params"
require "./sig_helper"
struct Invidious::DecryptFunction
class Invidious::DecryptFunction
@last_update : Time = Time.utc - 42.days
def initialize
def initialize(uri_or_path)
@client = SigHelper::Client.new(uri_or_path)
self.check_update
end
@@ -16,19 +17,18 @@ struct Invidious::DecryptFunction
# Get the time when the player was updated, in the event where
# multiple invidious processes are run in parallel.
player_ts = Invidious::SigHelper::Client.get_player_timestamp
player_time = Time.unix(player_ts || 0)
player_time = Time.unix(@client.get_player_timestamp || 0)
if (now - player_time) > 5.minutes
LOGGER.debug("Signature: Player might be outdated, updating")
Invidious::SigHelper::Client.force_update
@client.force_update
@last_update = Time.utc
end
end
def decrypt_nsig(n : String) : String?
self.check_update
return SigHelper::Client.decrypt_n_param(n)
return @client.decrypt_n_param(n)
rescue ex
LOGGER.debug(ex.message || "Signature: Unknown error")
LOGGER.trace(ex.inspect_with_backtrace)
@@ -37,7 +37,7 @@ struct Invidious::DecryptFunction
def decrypt_signature(str : String) : String?
self.check_update
return SigHelper::Client.decrypt_sig(str)
return @client.decrypt_sig(str)
rescue ex
LOGGER.debug(ex.message || "Signature: Unknown error")
LOGGER.trace(ex.inspect_with_backtrace)
@@ -46,7 +46,7 @@ struct Invidious::DecryptFunction
def get_sts : UInt64?
self.check_update
return SigHelper::Client.get_signature_timestamp
return @client.get_signature_timestamp
rescue ex
LOGGER.debug(ex.message || "Signature: Unknown error")
LOGGER.trace(ex.inspect_with_backtrace)