mirror of
https://github.com/iv-org/invidious.git
synced 2025-07-18 11:28:31 +00:00
Merge pull request #27 from catspeed-cc/new-dev-token-updater
Merge: new-dev-token-updater to new-development
This commit is contained in:
commit
2ec29a3488
@ -36,6 +36,10 @@ shards:
|
|||||||
git: https://github.com/will/crystal-pg.git
|
git: https://github.com/will/crystal-pg.git
|
||||||
version: 0.24.0
|
version: 0.24.0
|
||||||
|
|
||||||
|
pool:
|
||||||
|
git: https://github.com/ysbaddaden/pool.git
|
||||||
|
version: 0.2.4
|
||||||
|
|
||||||
protodec:
|
protodec:
|
||||||
git: https://github.com/iv-org/protodec.git
|
git: https://github.com/iv-org/protodec.git
|
||||||
version: 0.1.5
|
version: 0.1.5
|
||||||
@ -44,6 +48,10 @@ shards:
|
|||||||
git: https://github.com/luislavena/radix.git
|
git: https://github.com/luislavena/radix.git
|
||||||
version: 0.4.1
|
version: 0.4.1
|
||||||
|
|
||||||
|
redis:
|
||||||
|
git: https://github.com/stefanwille/crystal-redis.git
|
||||||
|
version: 2.9.1
|
||||||
|
|
||||||
spectator:
|
spectator:
|
||||||
git: https://github.com/icy-arctic-fox/spectator.git
|
git: https://github.com/icy-arctic-fox/spectator.git
|
||||||
version: 0.10.6
|
version: 0.10.6
|
||||||
|
@ -28,6 +28,8 @@ dependencies:
|
|||||||
athena-negotiation:
|
athena-negotiation:
|
||||||
github: athena-framework/negotiation
|
github: athena-framework/negotiation
|
||||||
version: ~> 0.1.1
|
version: ~> 0.1.1
|
||||||
|
redis:
|
||||||
|
github: stefanwille/crystal-redis
|
||||||
http_proxy:
|
http_proxy:
|
||||||
github: mamantoha/http_proxy
|
github: mamantoha/http_proxy
|
||||||
version: ~> 0.10.3
|
version: ~> 0.10.3
|
||||||
|
@ -32,6 +32,7 @@ require "xml"
|
|||||||
require "yaml"
|
require "yaml"
|
||||||
require "compress/zip"
|
require "compress/zip"
|
||||||
require "protodec/utils"
|
require "protodec/utils"
|
||||||
|
require "redis"
|
||||||
|
|
||||||
require "./invidious/database/*"
|
require "./invidious/database/*"
|
||||||
require "./invidious/database/migrations/*"
|
require "./invidious/database/migrations/*"
|
||||||
@ -62,6 +63,11 @@ CONFIG = Config.load
|
|||||||
HMAC_KEY = CONFIG.hmac_key
|
HMAC_KEY = CONFIG.hmac_key
|
||||||
|
|
||||||
PG_DB = DB.open CONFIG.database_url
|
PG_DB = DB.open CONFIG.database_url
|
||||||
|
REDIS_DB = Redis::PooledClient.new(unixsocket: CONFIG.redis_socket || nil, url: CONFIG.redis_url || nil)
|
||||||
|
|
||||||
|
if REDIS_DB.ping
|
||||||
|
puts "Connected to redis"
|
||||||
|
end
|
||||||
ARCHIVE_URL = URI.parse("https://archive.org")
|
ARCHIVE_URL = URI.parse("https://archive.org")
|
||||||
PUBSUB_URL = URI.parse("https://pubsubhubbub.appspot.com")
|
PUBSUB_URL = URI.parse("https://pubsubhubbub.appspot.com")
|
||||||
REDDIT_URL = URI.parse("https://www.reddit.com")
|
REDDIT_URL = URI.parse("https://www.reddit.com")
|
||||||
|
@ -87,6 +87,9 @@ class Config
|
|||||||
# Used for crawling channels: threads should check all videos uploaded by a channel
|
# Used for crawling channels: threads should check all videos uploaded by a channel
|
||||||
property full_refresh : Bool = false
|
property full_refresh : Bool = false
|
||||||
|
|
||||||
|
property redis_url : String?
|
||||||
|
property redis_socket : String?
|
||||||
|
|
||||||
# Jobs config structure. See jobs.cr and jobs/base_job.cr
|
# Jobs config structure. See jobs.cr and jobs/base_job.cr
|
||||||
property jobs = Invidious::Jobs::JobsConfig.new
|
property jobs = Invidious::Jobs::JobsConfig.new
|
||||||
|
|
||||||
|
@ -47,6 +47,15 @@ module Invidious::Database::Videos
|
|||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
SQL
|
SQL
|
||||||
|
|
||||||
return PG_DB.query_one?(request, id, as: Video)
|
if ((info = REDIS_DB.get(id)) && (time = REDIS_DB.get(id + ":time")))
|
||||||
|
return Video.new({
|
||||||
|
id: id,
|
||||||
|
info: JSON.parse(info).as_h,
|
||||||
|
updated: Time.parse(time, "%Y-%m-%d %H:%M:%S %z", Time::Location::UTC),
|
||||||
|
})
|
||||||
|
else
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -175,8 +175,9 @@ module Invidious::SigHelper
|
|||||||
@queue = {} of TransactionID => Transaction
|
@queue = {} of TransactionID => Transaction
|
||||||
|
|
||||||
@conn : Connection
|
@conn : Connection
|
||||||
|
@uri_or_path : String
|
||||||
|
|
||||||
def initialize(uri_or_path)
|
def initialize(@uri_or_path)
|
||||||
@conn = Connection.new(uri_or_path)
|
@conn = Connection.new(uri_or_path)
|
||||||
listen
|
listen
|
||||||
end
|
end
|
||||||
@ -186,10 +187,26 @@ module Invidious::SigHelper
|
|||||||
|
|
||||||
LOGGER.debug("SigHelper: Multiplexor listening")
|
LOGGER.debug("SigHelper: Multiplexor listening")
|
||||||
|
|
||||||
# TODO: reopen socket if unexpectedly closed
|
|
||||||
spawn do
|
spawn do
|
||||||
loop do
|
loop do
|
||||||
|
begin
|
||||||
receive_data
|
receive_data
|
||||||
|
rescue ex
|
||||||
|
LOGGER.info("SigHelper: Connection to helper died with '#{ex.message}' trying to reconnect...")
|
||||||
|
# We close the socket because for some reason is not closed.
|
||||||
|
@conn.close
|
||||||
|
loop do
|
||||||
|
begin
|
||||||
|
@conn = Connection.new(@uri_or_path)
|
||||||
|
LOGGER.info("SigHelper: Reconnected to SigHelper!")
|
||||||
|
rescue ex
|
||||||
|
LOGGER.debug("SigHelper: Reconnection to helper unsuccessful with error '#{ex.message}'. Retrying")
|
||||||
|
sleep 500.milliseconds
|
||||||
|
next
|
||||||
|
end
|
||||||
|
break if !@conn.closed?
|
||||||
|
end
|
||||||
|
end
|
||||||
Fiber.yield
|
Fiber.yield
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -305,7 +305,7 @@ def get_video(id, refresh = true, region = nil, force_refresh = false)
|
|||||||
video.schema_version != Video::SCHEMA_VERSION # cache control
|
video.schema_version != Video::SCHEMA_VERSION # cache control
|
||||||
begin
|
begin
|
||||||
video = fetch_video(id, region)
|
video = fetch_video(id, region)
|
||||||
Invidious::Database::Videos.update(video)
|
Invidious::Database::Videos.insert(video)
|
||||||
rescue ex
|
rescue ex
|
||||||
Invidious::Database::Videos.delete(id)
|
Invidious::Database::Videos.delete(id)
|
||||||
raise ex
|
raise ex
|
||||||
|
Loading…
Reference in New Issue
Block a user