Mega: Fixed mega in anonymous mode

Co-authored-by: Shivam Jha <lzzy12@users.noreply.github.com>
This commit is contained in:
Hafitz Setya 2021-04-26 21:29:52 +07:00 committed by GitHub
parent 5e1f05d5e3
commit 0e583811e4
Signed by untrusted user: GitHub
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -111,18 +111,23 @@ except KeyError:
MEGA_KEY = None
LOGGER.info('MEGA API KEY NOT AVAILABLE')
if MEGA_KEY is not None:
# Start megasdkrest binary
subprocess.Popen(["megasdkrest", "--apikey", MEGA_KEY])
time.sleep(3) # Wait for the mega server to start listening
mega_client = MegaSdkRestClient('http://localhost:6090')
try:
MEGA_USERNAME = getConfig('MEGA_USERNAME')
MEGA_PASSWORD = getConfig('MEGA_PASSWORD')
# Start megasdkrest binary
subprocess.Popen(["megasdkrest", "--apikey", MEGA_KEY])
time.sleep(3)
mega_client = MegaSdkRestClient('http://localhost:6090')
try:
mega_client.login(MEGA_USERNAME, MEGA_PASSWORD)
except mega_err.MegaSdkRestClientException as e:
logging.error(e.message['message'])
exit(0)
if len(MEGA_USERNAME) > 0 and len(MEGA_PASSWORD) > 0:
try:
mega_client.login(MEGA_USERNAME, MEGA_PASSWORD)
except mega_err.MegaSdkRestClientException as e:
logging.error(e.message['message'])
exit(0)
else:
LOGGER.info("Mega API KEY provided but credentials not provided. Starting mega in anonymous mode!")
MEGA_USERNAME = None
MEGA_PASSWORD = None
except KeyError:
LOGGER.info("Mega API KEY provided but credentials not provided. Starting mega in anonymous mode!")
MEGA_USERNAME = None