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 MEGA_KEY = None
LOGGER.info('MEGA API KEY NOT AVAILABLE') LOGGER.info('MEGA API KEY NOT AVAILABLE')
if MEGA_KEY is not None: 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: try:
MEGA_USERNAME = getConfig('MEGA_USERNAME') MEGA_USERNAME = getConfig('MEGA_USERNAME')
MEGA_PASSWORD = getConfig('MEGA_PASSWORD') MEGA_PASSWORD = getConfig('MEGA_PASSWORD')
# Start megasdkrest binary if len(MEGA_USERNAME) > 0 and len(MEGA_PASSWORD) > 0:
subprocess.Popen(["megasdkrest", "--apikey", MEGA_KEY]) try:
time.sleep(3) mega_client.login(MEGA_USERNAME, MEGA_PASSWORD)
mega_client = MegaSdkRestClient('http://localhost:6090') except mega_err.MegaSdkRestClientException as e:
try: logging.error(e.message['message'])
mega_client.login(MEGA_USERNAME, MEGA_PASSWORD) exit(0)
except mega_err.MegaSdkRestClientException as e: else:
logging.error(e.message['message']) LOGGER.info("Mega API KEY provided but credentials not provided. Starting mega in anonymous mode!")
exit(0) MEGA_USERNAME = None
MEGA_PASSWORD = None
except KeyError: except KeyError:
LOGGER.info("Mega API KEY provided but credentials not provided. Starting mega in anonymous mode!") LOGGER.info("Mega API KEY provided but credentials not provided. Starting mega in anonymous mode!")
MEGA_USERNAME = None MEGA_USERNAME = None