mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 09:42:02 +08:00
DEV: use different MaxMindDB download endpoint
This commit is contained in:
parent
dbd14a805c
commit
82f162962f
|
@ -27,28 +27,18 @@ class DiscourseIpInfo
|
|||
def self.mmdb_download(name)
|
||||
FileUtils.mkdir_p(path)
|
||||
|
||||
tar_gz_file = FileHelper.download(
|
||||
"https://geolite.maxmind.com/download/geoip/database/#{name}.tar.gz",
|
||||
gz_file = FileHelper.download(
|
||||
"https://geolite.maxmind.com/geoip/databases/#{name}/update",
|
||||
max_file_size: 100.megabytes,
|
||||
tmp_file_name: "#{name}.tar.gz"
|
||||
tmp_file_name: "#{name}.gz"
|
||||
)
|
||||
|
||||
dest = File.join(Dir.tmpdir, "maxmind_#{SecureRandom.hex}")
|
||||
FileUtils.mkdir_p(dest)
|
||||
|
||||
Discourse::Utils.execute_command('tar', '-xzvf', tar_gz_file.path, "-C", dest)
|
||||
|
||||
Dir.glob("#{dest}/**/*.mmdb").each do |path|
|
||||
if path.include?(name)
|
||||
FileUtils.mv(path, mmdb_path(name))
|
||||
else
|
||||
Rails.logger.warn("Skipping unknown mmdb file during ip database update #{path}")
|
||||
end
|
||||
end
|
||||
path = gz_file.path.sub(/\.gz\z/, "")
|
||||
Discourse::Utils.execute_command("gunzip", path)
|
||||
|
||||
FileUtils.mv(path, mmdb_path(name))
|
||||
ensure
|
||||
FileUtils.rm_rf(dest) if dest
|
||||
FileUtils.rm(tar_gz_file) if tar_gz_file
|
||||
gz_file.close!
|
||||
end
|
||||
|
||||
def mmdb_load(filepath)
|
||||
|
|
Loading…
Reference in New Issue
Block a user