Fix downloading GeoIP database

fixes #222
This commit is contained in:
caryoscelus 2023-07-29 17:17:06 +00:00
parent 714729edab
commit e79924d502

View file

@ -602,7 +602,7 @@ class UiWebsocketPlugin(object):
def downloadGeoLiteDb(self, db_path): def downloadGeoLiteDb(self, db_path):
import gzip import gzip
import shutil import shutil
from util import helper import requests
if config.offline or config.tor == 'always': if config.offline or config.tor == 'always':
return False return False
@ -617,18 +617,17 @@ class UiWebsocketPlugin(object):
downloadl_err = None downloadl_err = None
try: try:
# Download # Download
response = helper.httpRequest(db_url) response = requests.get(db_url, stream=True)
data_size = response.getheader('content-length') data_size = response.headers.get('content-length')
if data_size is None:
data.write(response.content)
data_size = int(data_size)
data_recv = 0 data_recv = 0
data = io.BytesIO() data = io.BytesIO()
while True: for buff in response.iter_content(chunk_size=1024 * 512):
buff = response.read(1024 * 512)
if not buff:
break
data.write(buff) data.write(buff)
data_recv += 1024 * 512 data_recv += 1024 * 512
if data_size: progress = int(float(data_recv) / data_size * 100)
progress = int(float(data_recv) / int(data_size) * 100)
self.cmd("progress", ["geolite-info", _["Downloading GeoLite2 City database (one time only, ~20MB)..."], progress]) self.cmd("progress", ["geolite-info", _["Downloading GeoLite2 City database (one time only, ~20MB)..."], progress])
self.log.info("GeoLite2 City database downloaded (%s bytes), unpacking..." % data.tell()) self.log.info("GeoLite2 City database downloaded (%s bytes), unpacking..." % data.tell())
data.seek(0) data.seek(0)