From e4fe2dd907d9455a66e69773459840c4e20cb005 Mon Sep 17 00:00:00 2001 From: misyaguziya Date: Tue, 30 Jul 2024 15:37:58 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7[WIP/TEST]=20Controller=20:=20?= =?UTF-8?q?=E5=BF=9C=E7=AD=94=E5=80=A4=E3=82=92=E4=BF=AE=E6=AD=A3/?= =?UTF-8?q?=E5=90=84=E3=82=BB=E3=82=AF=E3=82=B7=E3=83=A7=E3=83=B3=E3=81=A7?= =?UTF-8?q?process.log=E3=81=AB=E6=9B=B8=E3=81=8D=E5=87=BA=E3=81=99?= =?UTF-8?q?=E7=94=A8=E3=81=AB=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-python/webui_controller.py | 6 ++-- src-python/webui_mainloop.py | 64 ++++++++++++++++++++-------------- 2 files changed, 41 insertions(+), 29 deletions(-) diff --git a/src-python/webui_controller.py b/src-python/webui_controller.py index f97fd1d8..28d246c6 100644 --- a/src-python/webui_controller.py +++ b/src-python/webui_controller.py @@ -83,7 +83,7 @@ class MicMessage: addSentMessageLog(message) translation = "" if model.checkKeywords(message): - self.action({"status":"error", f"message":"Detected by word filter:{message}"}) + self.action({"status":"error", "message":f"Detected by word filter:{message}"}) return elif model.detectRepeatSendMessage(message): return @@ -416,12 +416,12 @@ def callbackEnableTranslation(*args, **kwargs) -> dict: config.ENABLE_TRANSLATION = True if model.isLoadedCTranslate2Model() is False: model.changeTranslatorCTranslate2Model() - return {"status":"success"} + return {"status":"success", "data":config.ENABLE_TRANSLATION} def callbackDisableTranslation(*args, **kwargs) -> dict: print("callbackDisableTranslation") config.ENABLE_TRANSLATION = False - return {"status":"success"} + return {"status":"success", "data":config.ENABLE_TRANSLATION} def callbackEnableTranscriptionSend(data, action, *args, **kwargs) -> dict: print("callbackEnableTranscriptionSend") diff --git a/src-python/webui_mainloop.py b/src-python/webui_mainloop.py index 315cee44..f799cab9 100644 --- a/src-python/webui_mainloop.py +++ b/src-python/webui_mainloop.py @@ -221,37 +221,49 @@ def main(): received_data = sys.stdin.readline().strip() received_data = json.loads(received_data) - if received_data is True: - response_data = { - "status": "ok", - "id": received_data["id"], - "data": received_data["data"], - } - response = json.dumps(response_data) - time.sleep(2) - print(response, flush=True) + with open('process.log', 'a') as f: + f.write(f"received_data: {received_data}\n") - # endpoint = received_data.get("endpoint", None) - # data = received_data.get("data", None) - - # match endpoint.split("/")[1]: - # case "config": - # response_data, status = handleConfigRequest(endpoint, data) - # case "controller": - # response_data, status = handleControllerRequest(endpoint, data) - # case _: - # pass - - # response = { - # "status": status, - # "endpoint": endpoint, - # "data": response_data, + if received_data: + # response_data = { + # "status": 200, + # "id": received_data["id"], + # "data": received_data["data"], # } - - # response = json.dumps(response) + # response = json.dumps(response_data) # time.sleep(2) # print(response, flush=True) + endpoint = received_data.get("endpoint", None) + data = received_data.get("data", None) + + with open('process.log', 'a') as f: + f.write(f"received_data : endpoint: {endpoint}, data:{data}\n") + + try: + match endpoint.split("/")[1]: + case "config": + result_data, status = handleConfigRequest(endpoint, data) + case "controller": + result_data, status = handleControllerRequest(endpoint, data) + case _: + pass + except Exception as e: + result_data = str(e) + status = 500 + + response = { + "status": status, + "endpoint": endpoint, + "result": result_data, + } + + response = json.dumps(response) + with open('process.log', 'a') as f: + f.write(f"response: {response}\n") + + print(response, flush=True) + if __name__ == "__main__": # endpoint = "/controller/list_mic_host" # data = None