mirror of
https://github.com/iv-org/invidious.git
synced 2025-05-31 14:11:54 +05:30
@@ -30,11 +30,8 @@ require "./invidious/*"
|
||||
require "./invidious/routes/**"
|
||||
require "./invidious/jobs/**"
|
||||
|
||||
ENV_CONFIG_NAME = "INVIDIOUS_CONFIG"
|
||||
|
||||
CONFIG_STR = ENV.has_key?(ENV_CONFIG_NAME) ? ENV.fetch(ENV_CONFIG_NAME) : File.read("config/config.yml")
|
||||
CONFIG = Config.from_yaml(CONFIG_STR)
|
||||
HMAC_KEY = CONFIG.hmac_key || Random::Secure.hex(32)
|
||||
CONFIG = Config.load
|
||||
HMAC_KEY = CONFIG.hmac_key || Random::Secure.hex(32)
|
||||
|
||||
PG_URL = URI.new(
|
||||
scheme: "postgres",
|
||||
@@ -52,7 +49,7 @@ PUBSUB_URL = URI.parse("https://pubsubhubbub.appspot.com")
|
||||
REDDIT_URL = URI.parse("https://www.reddit.com")
|
||||
TEXTCAPTCHA_URL = URI.parse("https://textcaptcha.com")
|
||||
YT_URL = URI.parse("https://www.youtube.com")
|
||||
HOST_URL = make_host_url(CONFIG, Kemal.config)
|
||||
HOST_URL = make_host_url(Kemal.config)
|
||||
|
||||
CHARS_SAFE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
|
||||
TEST_IDS = {"AgbeGFYluEA", "BaW_jenozKc", "a9LDPn-MO4I", "ddFvjfvPnqk", "iqKdEhx-dD4"}
|
||||
@@ -145,8 +142,6 @@ end
|
||||
OUTPUT = CONFIG.output.upcase == "STDOUT" ? STDOUT : File.open(CONFIG.output, mode: "a")
|
||||
LOGGER = Invidious::LogHandler.new(OUTPUT, CONFIG.log_level)
|
||||
|
||||
config = CONFIG
|
||||
|
||||
# Check table integrity
|
||||
if CONFIG.check_tables
|
||||
check_enum(PG_DB, "privacy", PlaylistPrivacy)
|
||||
@@ -167,28 +162,33 @@ end
|
||||
|
||||
# Start jobs
|
||||
|
||||
Invidious::Jobs.register Invidious::Jobs::RefreshChannelsJob.new(PG_DB, config)
|
||||
Invidious::Jobs.register Invidious::Jobs::RefreshFeedsJob.new(PG_DB, config)
|
||||
if CONFIG.channel_threads > 0
|
||||
Invidious::Jobs.register Invidious::Jobs::RefreshChannelsJob.new(PG_DB)
|
||||
end
|
||||
|
||||
if CONFIG.feed_threads > 0
|
||||
Invidious::Jobs.register Invidious::Jobs::RefreshFeedsJob.new(PG_DB)
|
||||
end
|
||||
|
||||
DECRYPT_FUNCTION = DecryptFunction.new(CONFIG.decrypt_polling)
|
||||
if config.decrypt_polling
|
||||
if CONFIG.decrypt_polling
|
||||
Invidious::Jobs.register Invidious::Jobs::UpdateDecryptFunctionJob.new
|
||||
end
|
||||
|
||||
if config.statistics_enabled
|
||||
Invidious::Jobs.register Invidious::Jobs::StatisticsRefreshJob.new(PG_DB, config, SOFTWARE)
|
||||
if CONFIG.statistics_enabled
|
||||
Invidious::Jobs.register Invidious::Jobs::StatisticsRefreshJob.new(PG_DB, SOFTWARE)
|
||||
end
|
||||
|
||||
if (config.use_pubsub_feeds.is_a?(Bool) && config.use_pubsub_feeds.as(Bool)) || (config.use_pubsub_feeds.is_a?(Int32) && config.use_pubsub_feeds.as(Int32) > 0)
|
||||
Invidious::Jobs.register Invidious::Jobs::SubscribeToFeedsJob.new(PG_DB, config, HMAC_KEY)
|
||||
if (CONFIG.use_pubsub_feeds.is_a?(Bool) && CONFIG.use_pubsub_feeds.as(Bool)) || (CONFIG.use_pubsub_feeds.is_a?(Int32) && CONFIG.use_pubsub_feeds.as(Int32) > 0)
|
||||
Invidious::Jobs.register Invidious::Jobs::SubscribeToFeedsJob.new(PG_DB, HMAC_KEY)
|
||||
end
|
||||
|
||||
if config.popular_enabled
|
||||
if CONFIG.popular_enabled
|
||||
Invidious::Jobs.register Invidious::Jobs::PullPopularVideosJob.new(PG_DB)
|
||||
end
|
||||
|
||||
if config.captcha_key
|
||||
Invidious::Jobs.register Invidious::Jobs::BypassCaptchaJob.new(config)
|
||||
if CONFIG.captcha_key
|
||||
Invidious::Jobs.register Invidious::Jobs::BypassCaptchaJob.new
|
||||
end
|
||||
|
||||
connection_channel = Channel({Bool, Channel(PQ::Notification)}).new(32)
|
||||
@@ -219,7 +219,7 @@ before_all do |env|
|
||||
env.response.headers["Content-Security-Policy"] = "default-src 'none'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self' data:; connect-src 'self'; manifest-src 'self'; media-src 'self' blob:#{extra_media_csp}"
|
||||
env.response.headers["Referrer-Policy"] = "same-origin"
|
||||
|
||||
if (Kemal.config.ssl || config.https_only) && config.hsts
|
||||
if (Kemal.config.ssl || CONFIG.https_only) && CONFIG.hsts
|
||||
env.response.headers["Strict-Transport-Security"] = "max-age=31536000; includeSubDomains; preload"
|
||||
end
|
||||
|
||||
@@ -1164,7 +1164,7 @@ end
|
||||
get "/feed/popular" do |env|
|
||||
locale = LOCALES[env.get("preferences").as(Preferences).locale]?
|
||||
|
||||
if config.popular_enabled
|
||||
if CONFIG.popular_enabled
|
||||
templated "popular"
|
||||
else
|
||||
message = translate(locale, "The Popular feed has been disabled by the administrator.")
|
||||
@@ -1822,7 +1822,7 @@ get "/api/v1/stats" do |env|
|
||||
locale = LOCALES[env.get("preferences").as(Preferences).locale]?
|
||||
env.response.content_type = "application/json"
|
||||
|
||||
if !config.statistics_enabled
|
||||
if !CONFIG.statistics_enabled
|
||||
next error_json(400, "Statistics are not enabled.")
|
||||
end
|
||||
|
||||
@@ -2232,7 +2232,7 @@ get "/api/v1/popular" do |env|
|
||||
|
||||
env.response.content_type = "application/json"
|
||||
|
||||
if !config.popular_enabled
|
||||
if !CONFIG.popular_enabled
|
||||
error_message = {"error" => "Administrator has disabled this endpoint."}.to_json
|
||||
env.response.status_code = 400
|
||||
next error_message
|
||||
|
Reference in New Issue
Block a user