👍️[Update] Model : tauri -> python のデータ部分をbase64でencodeするように修正
This commit is contained in:
6
package-lock.json
generated
6
package-lock.json
generated
@@ -19,6 +19,7 @@
|
|||||||
"eslint-plugin-react": "^7.34.2",
|
"eslint-plugin-react": "^7.34.2",
|
||||||
"i18next": "^23.11.5",
|
"i18next": "^23.11.5",
|
||||||
"jotai": "^2.8.3",
|
"jotai": "^2.8.3",
|
||||||
|
"js-base64": "^3.7.7",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
"react-i18next": "^14.1.2",
|
"react-i18next": "^14.1.2",
|
||||||
@@ -4360,6 +4361,11 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/js-base64": {
|
||||||
|
"version": "3.7.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/js-base64/-/js-base64-3.7.7.tgz",
|
||||||
|
"integrity": "sha512-7rCnleh0z2CkXhH67J8K1Ytz0b2Y+yxTPL+/KOJoa20hfnVQ/3/T6W/KflYI4bRHRagNeXeU2bkNGI3v1oS/lw=="
|
||||||
|
},
|
||||||
"node_modules/js-tokens": {
|
"node_modules/js-tokens": {
|
||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
"eslint-plugin-react": "^7.34.2",
|
"eslint-plugin-react": "^7.34.2",
|
||||||
"i18next": "^23.11.5",
|
"i18next": "^23.11.5",
|
||||||
"jotai": "^2.8.3",
|
"jotai": "^2.8.3",
|
||||||
|
"js-base64": "^3.7.7",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
"react-i18next": "^14.1.2",
|
"react-i18next": "^14.1.2",
|
||||||
|
|||||||
@@ -73,13 +73,5 @@ def splitList(lst:list, split_count:int, to_shuffle:bool=False):
|
|||||||
split_lists.append(sub_list)
|
split_lists.append(sub_list)
|
||||||
return split_lists
|
return split_lists
|
||||||
|
|
||||||
def encodeUtf8(data:str) -> dict:
|
|
||||||
data = {i: byte for i, byte in enumerate(data.encode('UTF-8'))}
|
|
||||||
return data
|
|
||||||
|
|
||||||
def decodeUtf8(data:dict) -> str:
|
|
||||||
data = bytes(data.values()).decode("UTF-8")
|
|
||||||
return data
|
|
||||||
|
|
||||||
def printLog(log:str, data:Any=None) -> None:
|
def printLog(log:str, data:Any=None) -> None:
|
||||||
print(json.dumps({"status":348, "log":log, "data":str(data)}), flush=True)
|
print(json.dumps({"status":348, "log":log, "data":str(data)}), flush=True)
|
||||||
@@ -5,7 +5,7 @@ from subprocess import Popen
|
|||||||
from threading import Thread
|
from threading import Thread
|
||||||
from config import config
|
from config import config
|
||||||
from model import model
|
from model import model
|
||||||
from utils import getKeyByValue, isUniqueStrings, decodeUtf8, encodeUtf8, printLog
|
from utils import getKeyByValue, isUniqueStrings, printLog
|
||||||
|
|
||||||
# Common
|
# Common
|
||||||
class DownloadSoftwareProgressBar:
|
class DownloadSoftwareProgressBar:
|
||||||
@@ -289,7 +289,7 @@ class ChatMessage:
|
|||||||
|
|
||||||
def send(self, data):
|
def send(self, data):
|
||||||
id = data["id"]
|
id = data["id"]
|
||||||
message = decodeUtf8(data["message"])
|
message = data["message"]
|
||||||
if len(message) > 0:
|
if len(message) > 0:
|
||||||
# addSentMessageLog(message)
|
# addSentMessageLog(message)
|
||||||
translation = ""
|
translation = ""
|
||||||
@@ -329,8 +329,6 @@ class ChatMessage:
|
|||||||
translation = f" ({translation})"
|
translation = f" ({translation})"
|
||||||
model.logger.info(f"[SENT] {message}{translation}")
|
model.logger.info(f"[SENT] {message}{translation}")
|
||||||
|
|
||||||
message = encodeUtf8(message)
|
|
||||||
translation = encodeUtf8(translation)
|
|
||||||
return {"status":200,
|
return {"status":200,
|
||||||
"result":{
|
"result":{
|
||||||
"id":id,
|
"id":id,
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ import json
|
|||||||
import time
|
import time
|
||||||
from config import config
|
from config import config
|
||||||
import webui_controller as controller
|
import webui_controller as controller
|
||||||
from utils import printLog, encodeUtf8
|
from utils import printLog
|
||||||
|
import base64
|
||||||
|
|
||||||
config_mapping = {
|
config_mapping = {
|
||||||
"/config/version": "VERSION",
|
"/config/version": "VERSION",
|
||||||
@@ -288,6 +289,8 @@ def main():
|
|||||||
if received_data:
|
if received_data:
|
||||||
endpoint = received_data.get("endpoint", None)
|
endpoint = received_data.get("endpoint", None)
|
||||||
data = received_data.get("data", None)
|
data = received_data.get("data", None)
|
||||||
|
if data is not None:
|
||||||
|
data = json.loads(base64.b64decode(data).decode('utf-8'))
|
||||||
|
|
||||||
with open('process.log', 'a') as f:
|
with open('process.log', 'a') as f:
|
||||||
f.write(f"received_data : endpoint: {endpoint}, data:{data}\n")
|
f.write(f"received_data : endpoint: {endpoint}, data:{data}\n")
|
||||||
@@ -367,7 +370,7 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
match endpoint:
|
match endpoint:
|
||||||
case "/controller/callback_messagebox_send":
|
case "/controller/callback_messagebox_send":
|
||||||
data = {"id":"123456", "message":encodeUtf8("テスト")}
|
data = {"id":"123456", "message":"テスト"}
|
||||||
case "/controller/set_your_language_and_country":
|
case "/controller/set_your_language_and_country":
|
||||||
data = {"language": "English", "country": "Hong Kong"}
|
data = {"language": "English", "country": "Hong Kong"}
|
||||||
case "/controller/set_target_language_and_country":
|
case "/controller/set_target_language_and_country":
|
||||||
|
|||||||
@@ -7,14 +7,13 @@ import { useStdoutToPython } from "./useStdoutToPython";
|
|||||||
export const useMessage = () => {
|
export const useMessage = () => {
|
||||||
const { currentMessageLogsStatus, addMessageLogsStatus, updateMessageLogsStatus } = useMessageLogsStatus();
|
const { currentMessageLogsStatus, addMessageLogsStatus, updateMessageLogsStatus } = useMessageLogsStatus();
|
||||||
const { asyncStdoutToPython } = useStdoutToPython();
|
const { asyncStdoutToPython } = useStdoutToPython();
|
||||||
const encoder = new TextEncoder();
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
sendMessage: (message) => {
|
sendMessage: (message) => {
|
||||||
const uuid = crypto.randomUUID();
|
const uuid = crypto.randomUUID();
|
||||||
const send_message_object = {
|
const send_message_object = {
|
||||||
id: uuid,
|
id: uuid,
|
||||||
message: encoder.encode(message),
|
message: message,
|
||||||
};
|
};
|
||||||
asyncStdoutToPython("/controller/callback_messagebox_send", send_message_object);
|
asyncStdoutToPython("/controller/callback_messagebox_send", send_message_object);
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import { store } from "@store";
|
import { store } from "@store";
|
||||||
|
import { encode } from 'js-base64'
|
||||||
|
|
||||||
export const useStdoutToPython = () => {
|
export const useStdoutToPython = () => {
|
||||||
const asyncStdoutToPython = async (path, value) => {
|
const asyncStdoutToPython = async (path, value) => {
|
||||||
let send_object = { endpoint: path };
|
let send_object = { endpoint: path };
|
||||||
if (value) send_object.data = value;
|
if (value) send_object.data = encode(value);
|
||||||
|
|
||||||
// send to python
|
// send to python
|
||||||
const backend_subprocess = store.backend_subprocess;
|
const backend_subprocess = store.backend_subprocess;
|
||||||
|
|||||||
Reference in New Issue
Block a user