From 2f5938c3bfeb63d94f0a1a0b2a90f3cc272e8689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Fri, 24 May 2019 18:11:39 +0200 Subject: [PATCH] DEV: use FileHelper to download MaxMindDB --- lib/discourse_ip_info.rb | 14 +++++--------- lib/tasks/assets.rake | 10 ++-------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/lib/discourse_ip_info.rb b/lib/discourse_ip_info.rb index 5323bb2caee..40835bddee0 100644 --- a/lib/discourse_ip_info.rb +++ b/lib/discourse_ip_info.rb @@ -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) diff --git a/lib/tasks/assets.rake b/lib/tasks/assets.rake index d01b340e946..9fe3a485d60 100644 --- a/lib/tasks/assets.rake +++ b/lib/tasks/assets.rake @@ -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