eBooru/app/logical/cloudflare_service.rb
Earlopain d01c8c131d
[Misc] Replace httparty with faraday
We already pull in faraday from opensearch-ruby.
httparty hasn't had a release in a while and it printing warnings on ruby 3.3
2024-04-27 23:01:10 +02:00

20 lines
525 B
Ruby

# frozen_string_literal: true
module CloudflareService
def self.endpoint
"https://api.cloudflare.com/client/v4/ips"
end
def self.ips
text, status = Cache.fetch("cloudflare_ips", expires_in: 24.hours) do
resp = Faraday.new(Danbooru.config.faraday_options).get(endpoint)
[resp.body, resp.status]
end
return [] if status != 200
json = JSON.parse(text, symbolize_names: true)
ips = json[:result][:ipv4_cidrs] + json[:result][:ipv6_cidrs]
ips.map { |ip| IPAddr.new(ip) }
end
end