Some checks failed
Lock Threads / action (push) Has been cancelled
Mark stale issues and pull requests / stale (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot EE docker images / merge (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot CE docker images / merge (push) Has been cancelled
Run Chatwoot CE spec / lint-backend (push) Has been cancelled
Run Chatwoot CE spec / lint-frontend (push) Has been cancelled
Run Chatwoot CE spec / frontend-tests (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (0, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (1, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (10, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (11, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (12, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (13, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (14, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (15, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (2, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (3, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (4, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (5, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (6, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (7, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (8, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (9, 16) (push) Has been cancelled
Run Linux nightly installer / nightly (push) Has been cancelled
- Add Logistics component with progress tracking - Add OrderDetail component for order information - Support data-driven steps and actions - Add blue color scale to widget SCSS - Fix node overflow and progress bar rendering issues - Add English translations for dashboard components Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
50 lines
1.3 KiB
Ruby
50 lines
1.3 KiB
Ruby
require 'rubygems/package'
|
|
|
|
class Geocoder::SetupService
|
|
def perform
|
|
return if File.exist?(GeocoderConfiguration::LOOK_UP_DB)
|
|
|
|
ip_lookup_api_key = ENV.fetch('IP_LOOKUP_API_KEY', nil)
|
|
if ip_lookup_api_key.blank?
|
|
log_info('IP_LOOKUP_API_KEY empty. Skipping geoip database setup')
|
|
return
|
|
end
|
|
|
|
log_info('Fetch GeoLite2-City database')
|
|
fetch_and_extract_database(ip_lookup_api_key)
|
|
end
|
|
|
|
private
|
|
|
|
def fetch_and_extract_database(api_key)
|
|
base_url = ENV.fetch('IP_LOOKUP_BASE_URL', 'https://download.maxmind.com/app/geoip_download')
|
|
source_file = Down.download("#{base_url}?edition_id=GeoLite2-City&suffix=tar.gz&license_key=#{api_key}")
|
|
|
|
extract_tar_file(source_file)
|
|
log_info('Fetch complete')
|
|
rescue StandardError => e
|
|
log_error(e.message)
|
|
end
|
|
|
|
def extract_tar_file(source_file)
|
|
tar_extract = Gem::Package::TarReader.new(Zlib::GzipReader.open(source_file))
|
|
tar_extract.rewind
|
|
|
|
tar_extract.each do |entry|
|
|
next unless entry.full_name.include?('GeoLite2-City.mmdb') && entry.file?
|
|
|
|
File.open GeocoderConfiguration::LOOK_UP_DB, 'wb' do |f|
|
|
f.print entry.read
|
|
end
|
|
end
|
|
end
|
|
|
|
def log_info(message)
|
|
Rails.logger.info "[rake ip_lookup:setup] #{message}"
|
|
end
|
|
|
|
def log_error(message)
|
|
Rails.logger.error "[rake ip_lookup:setup] #{message}"
|
|
end
|
|
end
|