Fix #1333 - listen_port isn't always present in the config file

This commit is contained in:
cmdr2 2023-06-07 15:45:21 +05:30
parent 9a0031c47b
commit e23f66a697

View File

@ -338,21 +338,22 @@ def get_image_internal(task_id: int, img_id: int):
class CloudflareTunnel: class CloudflareTunnel:
def __init__(self): def __init__(self):
config = app.getConfig() config = app.getConfig()
self.Urls = None self.urls = None
self.port = config["net"]["listen_port"] self.port = config.get("net", {}).get("listen_port")
def start(self): def start(self):
self.Urls = try_cloudflare(self.port) if self.port:
self.urls = try_cloudflare(self.port)
def stop(self): def stop(self):
if self.Urls != None: if self.urls:
try_cloudflare.terminate(self.port) try_cloudflare.terminate(self.port)
self.Urls = None self.urls = None
@property @property
def address(self): def address(self):
if self.Urls != None: if self.urls:
return self.Urls.tunnel return self.urls.tunnel
else: else:
return None return None