Skip to content

Commit 01960db

Browse files
Mega: Fixed mega in anonymous mode
Signed-off-by: lzzy12 <jhashivam2020@gmail.com>
1 parent d3cfcd4 commit 01960db

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

bot/__init__.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,23 @@ def getConfig(name: str):
8888
MEGA_KEY = None
8989
LOGGER.info('MEGA API KEY NOT AVAILABLE')
9090
if MEGA_KEY is not None:
91+
# Start megasdkrest binary
92+
subprocess.Popen(["megasdkrest", "--apikey", MEGA_KEY])
93+
time.sleep(3) # Wait for the mega server to start listening
94+
mega_client = MegaSdkRestClient('http://localhost:6090')
9195
try:
9296
MEGA_USERNAME = getConfig('MEGA_USERNAME')
9397
MEGA_PASSWORD = getConfig('MEGA_PASSWORD')
94-
# Start megasdkrest binary
95-
subprocess.Popen(["megasdkrest", "--apikey", MEGA_KEY])
96-
time.sleep(3)
97-
mega_client = MegaSdkRestClient('http://localhost:6090')
98-
try:
99-
mega_client.login(MEGA_USERNAME, MEGA_PASSWORD)
100-
except mega_err.MegaSdkRestClientException as e:
101-
logging.error(e.message['message'])
102-
exit(0)
98+
if len(MEGA_USERNAME) > 0 and len(MEGA_PASSWORD) > 0:
99+
try:
100+
mega_client.login(MEGA_USERNAME, MEGA_PASSWORD)
101+
except mega_err.MegaSdkRestClientException as e:
102+
logging.error(e.message['message'])
103+
exit(0)
104+
else:
105+
LOGGER.info("Mega API KEY provided but credentials not provided. Starting mega in anonymous mode!")
106+
MEGA_USERNAME = None
107+
MEGA_PASSWORD = None
103108
except KeyError:
104109
LOGGER.info("Mega API KEY provided but credentials not provided. Starting mega in anonymous mode!")
105110
MEGA_USERNAME = None

0 commit comments

Comments
 (0)