mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 19:03:45 +08:00
DEV: use FileHelper to download MaxMindDB
This commit is contained in:
parent
963f6fbd40
commit
2f5938c3bf
|
@ -27,15 +27,11 @@ class DiscourseIpInfo
|
|||
def self.mmdb_download(name)
|
||||
FileUtils.mkdir_p(path)
|
||||
|
||||
uri = URI("https://geolite.maxmind.com/download/geoip/database/#{name}.tar.gz")
|
||||
|
||||
puts uri
|
||||
puts "SIZE: #{Net::HTTP.get(uri).size}"
|
||||
|
||||
tar_gz_file = Tempfile.new
|
||||
tar_gz_file.binmode
|
||||
tar_gz_file.write(Net::HTTP.get(uri))
|
||||
tar_gz_file.close
|
||||
tar_gz_file = FileHelper.download(
|
||||
"https://geolite.maxmind.com/download/geoip/database/#{name}.tar.gz",
|
||||
max_file_size: 100.megabytes,
|
||||
tmp_file_name: "#{name}.tar.gz"
|
||||
)
|
||||
|
||||
dest = File.join(Dir.tmpdir, "maxmind_#{SecureRandom.hex}")
|
||||
FileUtils.mkdir_p(dest)
|
||||
|
|
|
@ -165,14 +165,8 @@ task 'assets:precompile' => 'assets:precompile:before' do
|
|||
if !mmdb_time || mmdb_time < refresh_days.days.ago
|
||||
puts "Downloading MaxMindDB..."
|
||||
mmdb_thread = Thread.new do
|
||||
begin
|
||||
DiscourseIpInfo.mmdb_download('GeoLite2-City')
|
||||
DiscourseIpInfo.mmdb_download('GeoLite2-ASN')
|
||||
rescue => e
|
||||
puts "Something when wrong while downloading the MaxMindDB"
|
||||
puts e.message
|
||||
puts e.backtrace.join("\n")
|
||||
end
|
||||
DiscourseIpInfo.mmdb_download('GeoLite2-City')
|
||||
DiscourseIpInfo.mmdb_download('GeoLite2-ASN')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user