mirror of
https://github.com/iv-org/invidious.git
synced 2024-11-25 15:07:22 +00:00
Handle if inst. api is down for rand inst fetch
This commit is contained in:
parent
b393e31b76
commit
eb911de928
@ -411,12 +411,22 @@ def convert_theme(theme)
|
||||
end
|
||||
|
||||
def fetch_random_instance
|
||||
instance_list = HTTP::Client.get "https://api.invidious.io/instances.json"
|
||||
instance_list = JSON.parse(instance_list.body)
|
||||
begin
|
||||
instance_api_client = HTTP::Client.new("api.invidious.io")
|
||||
|
||||
# Timeouts
|
||||
instance_api_client.connect_timeout = 10.seconds
|
||||
instance_api_client.dns_timeout = 10.seconds
|
||||
|
||||
instance_list = JSON.parse(instance_api_client.get("/instances.json").body).as_a
|
||||
instance_api_client.close
|
||||
rescue Socket::ConnectError | IO::TimeoutError | JSON::ParseException
|
||||
instance_list = [] of JSON::Any
|
||||
end
|
||||
|
||||
filtered_instance_list = [] of String
|
||||
|
||||
instance_list.as_a.each do |data|
|
||||
instance_list.each do |data|
|
||||
# TODO Check if current URL is onion instance and use .onion types if so.
|
||||
if data[1]["type"] == "https"
|
||||
# Instances can have statisitics disabled, which is an requirement of version validation.
|
||||
|
Loading…
Reference in New Issue
Block a user