mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 18:51:08 +08:00
DEV: use different MaxMindDB download endpoint
This commit is contained in:
@ -27,28 +27,18 @@ class DiscourseIpInfo
|
|||||||
def self.mmdb_download(name)
|
def self.mmdb_download(name)
|
||||||
FileUtils.mkdir_p(path)
|
FileUtils.mkdir_p(path)
|
||||||
|
|
||||||
tar_gz_file = FileHelper.download(
|
gz_file = FileHelper.download(
|
||||||
"https://geolite.maxmind.com/download/geoip/database/#{name}.tar.gz",
|
"https://geolite.maxmind.com/geoip/databases/#{name}/update",
|
||||||
max_file_size: 100.megabytes,
|
max_file_size: 100.megabytes,
|
||||||
tmp_file_name: "#{name}.tar.gz"
|
tmp_file_name: "#{name}.gz"
|
||||||
)
|
)
|
||||||
|
|
||||||
dest = File.join(Dir.tmpdir, "maxmind_#{SecureRandom.hex}")
|
path = gz_file.path.sub(/\.gz\z/, "")
|
||||||
FileUtils.mkdir_p(dest)
|
Discourse::Utils.execute_command("gunzip", path)
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
|
FileUtils.mv(path, mmdb_path(name))
|
||||||
ensure
|
ensure
|
||||||
FileUtils.rm_rf(dest) if dest
|
gz_file.close!
|
||||||
FileUtils.rm(tar_gz_file) if tar_gz_file
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def mmdb_load(filepath)
|
def mmdb_load(filepath)
|
||||||
|
Reference in New Issue
Block a user