Fix for Android app

Fix for Android app
Android and iOS are sending requests to usersapi differently, this handles both gracefully
This commit is contained in:
Brian Martin 2019-02-05 10:36:37 -05:00
parent da286b7fa9
commit 8e1ba3a475

View file

@ -195,22 +195,29 @@ class ConfServer():
async def handle_usersapi(self, request): async def handle_usersapi(self, request):
body = {} body = {}
postbody = {}
json_body = json.loads(await request.text()) if request.content_type == "application/x-www-form-urlencoded":
todo = json_body['todo'] postbody = await request.post()
else:
postbody = json.loads(await request.text())
logging.debug(postbody)
todo = postbody['todo']
if todo == 'FindBest': if todo == 'FindBest':
service = json_body['service'] service = postbody['service']
if service == 'EcoMsgNew': if service == 'EcoMsgNew':
body = {"result":"ok","ip":socket.gethostbyname(socket.gethostname()),"port":5223} body = {"result":"ok","ip":socket.gethostbyname(socket.gethostname()),"port":5223}
elif service == 'EcoUpdate': elif service == 'EcoUpdate':
body = {"result":"ok","ip":"47.88.66.164","port":8005} body = {"result":"ok","ip":"47.88.66.164","port":8005}
elif todo == 'loginByItToken': elif todo == 'loginByItToken':
body = { body = {
"resource": json_body["resource"], "resource": postbody["resource"],
"result": "ok", "result": "ok",
"todo": "result", "todo": "result",
"token": json_body["token"], #RandomChar(32) "token": postbody["token"], #RandomChar(32)
"userId": json_body["userId"] #RandomChar(16) "userId": postbody["userId"] #RandomChar(16)
} }
elif todo == 'GetDeviceList': elif todo == 'GetDeviceList':
active_bots = self.bumper_bots.get() active_bots = self.bumper_bots.get()