From 3d53652b2dce55e2d11d788d4981463f4f6181f8 Mon Sep 17 00:00:00 2001 From: misyaguziya <53165965+misyaguziya@users.noreply.github.com> Date: Sat, 22 Mar 2025 14:37:05 +0900 Subject: [PATCH 1/3] [Update] Controller: Validate and handle IP address setting in setOscIpAddress method. [Update] Utils: Implement isValidIpAddress function to check IP address validity. --- src-python/controller.py | 27 +++++++++++++++++++++++---- src-python/utils.py | 10 +++++++++- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src-python/controller.py b/src-python/controller.py index f0356287..98b84844 100644 --- a/src-python/controller.py +++ b/src-python/controller.py @@ -6,7 +6,7 @@ import re from device_manager import device_manager from config import config from model import model -from utils import removeLog, printLog, errorLogging, isConnectedNetwork +from utils import removeLog, printLog, errorLogging, isConnectedNetwork, isValidIpAddress class Controller: def __init__(self) -> None: @@ -1085,9 +1085,28 @@ class Controller: @staticmethod def setOscIpAddress(data, *args, **kwargs) -> dict: - config.OSC_IP_ADDRESS = data - model.setOscIpAddress(config.OSC_IP_ADDRESS) - return {"status":200, "result":config.OSC_IP_ADDRESS} + if isValidIpAddress(data) is False: + return { + "status":400, + "result":{ + "message":"Invalid IP address", + "data": config.OSC_IP_ADDRESS + } + } + else: + try: + model.setOscIpAddress(data) + config.OSC_IP_ADDRESS = data + return {"status":200, "result":config.OSC_IP_ADDRESS} + except Exception: + model.setOscIpAddress(config.OSC_IP_ADDRESS) + return { + "status":400, + "result":{ + "message":"Cannot set IP address", + "data": config.OSC_IP_ADDRESS + } + } @staticmethod def getOscPort(*args, **kwargs) -> dict: diff --git a/src-python/utils.py b/src-python/utils.py index e31a1f46..de538dae 100644 --- a/src-python/utils.py +++ b/src-python/utils.py @@ -7,14 +7,22 @@ from logging.handlers import RotatingFileHandler from ctranslate2 import get_supported_compute_types import requests +import ipaddress -def isConnectedNetwork(url="http://www.google.com", timeout=3): +def isConnectedNetwork(url="http://www.google.com", timeout=3) -> bool: try: response = requests.get(url, timeout=timeout) return response.status_code == 200 except requests.RequestException: return False +def isValidIpAddress(ip_address: str) -> bool: + try: + ipaddress.ip_address(ip_address) + return True + except ValueError: + return False + def getBestComputeType(device, device_index) -> str: compute_types = get_supported_compute_types(device, device_index) compute_types = set(compute_types) From df344baa069d2ee2228243cb4a10731d1847e3c8 Mon Sep 17 00:00:00 2001 From: misyaguziya <53165965+misyaguziya@users.noreply.github.com> Date: Sat, 22 Mar 2025 14:43:52 +0900 Subject: [PATCH 2/3] [bugfix] Controller: Fix response handling in setOscIpAddress method. --- src-python/controller.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src-python/controller.py b/src-python/controller.py index 98b84844..df6267ff 100644 --- a/src-python/controller.py +++ b/src-python/controller.py @@ -1086,7 +1086,7 @@ class Controller: @staticmethod def setOscIpAddress(data, *args, **kwargs) -> dict: if isValidIpAddress(data) is False: - return { + response = { "status":400, "result":{ "message":"Invalid IP address", @@ -1097,16 +1097,17 @@ class Controller: try: model.setOscIpAddress(data) config.OSC_IP_ADDRESS = data - return {"status":200, "result":config.OSC_IP_ADDRESS} + response = {"status":200, "result":config.OSC_IP_ADDRESS} except Exception: model.setOscIpAddress(config.OSC_IP_ADDRESS) - return { + response = { "status":400, "result":{ "message":"Cannot set IP address", "data": config.OSC_IP_ADDRESS } } + return response @staticmethod def getOscPort(*args, **kwargs) -> dict: From a5e59af8850170edaf3ef8b87133a7e17778b1b9 Mon Sep 17 00:00:00 2001 From: Sakamoto Shiina <68018796+ShiinaSakamoto@users.noreply.github.com> Date: Sat, 22 Mar 2025 17:28:31 +0900 Subject: [PATCH 3/3] [Update] AdvancedSettings: OSC IP Address: Add error notifications. Add 500 status error message. --- src-ui/logics/_useBackendErrorHandling.js | 27 +++++++++++-------- .../advanced_settings/useOscIpAddress.js | 9 ------- src-ui/logics/useReceiveRoutes.js | 6 +++-- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src-ui/logics/_useBackendErrorHandling.js b/src-ui/logics/_useBackendErrorHandling.js index 1145cd80..5cca840f 100644 --- a/src-ui/logics/_useBackendErrorHandling.js +++ b/src-ui/logics/_useBackendErrorHandling.js @@ -15,9 +15,7 @@ import { useDeepLAuthKey, - useOscIpAddress, - useOscPort, } from "@logics_configs"; import { ui_configs } from "../ui_configs"; @@ -35,9 +33,7 @@ export const _useBackendErrorHandling = () => { const { updateDeepLAuthKey, saveErrorDeepLAuthKey } = useDeepLAuthKey(); - - const { saveErrorOscIpAddress } = useOscIpAddress(); - const { saveErrorOscPort } = useOscPort(); + const { updateOscIpAddress } = useOscIpAddress(); const errorHandling_Backend = ({message, data, endpoint, _result}) => { switch (message) { @@ -55,9 +51,9 @@ export const _useBackendErrorHandling = () => { break; case "Speaker energy threshold value is out of range": showNotification_Error(t("common_error.threshold_invalid_value", - { min: ui_configs.speaker_threshold_min, max: ui_configs.speaker_threshold_max }, - )); - break; + { min: ui_configs.speaker_threshold_min, max: ui_configs.speaker_threshold_max }, + )); + break; case "CTranslate2 weight download error": showNotification_Error(t("common_error.failed_download_weight_ctranslate2")); @@ -118,12 +114,21 @@ export const _useBackendErrorHandling = () => { showNotification_Error(t("common_error.invalid_value_speaker_max_phrase")); break; + + // Advanced Settings, error messages are set by Backend (EN only) + case "Invalid IP address": + updateOscIpAddress(data); + showNotification_Error(message); + break; + + case "Cannot set IP address": + updateOscIpAddress(data); + showNotification_Error(message); + break; + default: // determine by endpoint, not message. if (endpoint === "/set/data/deepl_auth_key") saveErrorDeepLAuthKey({message, data, endpoint, _result}); - if (endpoint === "/set/data/osc_ip_address") saveErrorOscIpAddress({message, data, endpoint, _result}); - if (endpoint === "/set/data/osc_port") saveErrorOscPort({message, data, endpoint, _result}); - break; } diff --git a/src-ui/logics/configs/advanced_settings/useOscIpAddress.js b/src-ui/logics/configs/advanced_settings/useOscIpAddress.js index 354e2751..702a6d98 100644 --- a/src-ui/logics/configs/advanced_settings/useOscIpAddress.js +++ b/src-ui/logics/configs/advanced_settings/useOscIpAddress.js @@ -1,9 +1,7 @@ import { useStore_OscIpAddress } from "@store"; import { useStdoutToPython } from "@logics/useStdoutToPython"; -import { useNotificationStatus } from "@logics_common"; export const useOscIpAddress = () => { - const { showNotification_Error } = useNotificationStatus(); const { asyncStdoutToPython } = useStdoutToPython(); const { currentOscIpAddress, updateOscIpAddress, pendingOscIpAddress } = useStore_OscIpAddress(); @@ -17,17 +15,10 @@ export const useOscIpAddress = () => { asyncStdoutToPython("/set/data/osc_ip_address", osc_ip_address); }; - const saveErrorOscIpAddress = ({data, message, _result}) => { - updateOscIpAddress(d => d.data); - showNotification_Error(_result); - }; - return { currentOscIpAddress, getOscIpAddress, updateOscIpAddress, setOscIpAddress, - - saveErrorOscIpAddress, }; }; \ No newline at end of file diff --git a/src-ui/logics/useReceiveRoutes.js b/src-ui/logics/useReceiveRoutes.js index 383f1faf..8df5dc46 100644 --- a/src-ui/logics/useReceiveRoutes.js +++ b/src-ui/logics/useReceiveRoutes.js @@ -525,7 +525,6 @@ export const useReceiveRoutes = () => { "/set/data/speaker_max_phrases": errorHandling_Backend, "/set/data/osc_ip_address": errorHandling_Backend, - "/set/data/osc_port": errorHandling_Backend, }; @@ -558,7 +557,6 @@ export const useReceiveRoutes = () => { break; case 400: - case 500: const error_route = error_status_routes[parsed_data.endpoint]; if (error_route) { error_route({ @@ -571,6 +569,10 @@ export const useReceiveRoutes = () => { handleInvalidEndpoint(parsed_data); } break; + case 500: + showNotification_Error( + `An error occurred. Please restart VRCT or contact the developers. ${JSON.stringify(parsed_data.result)}`, { hide_duration: null }); + break; case 348: // console.log(`from backend: %c ${JSON.stringify(parsed_data)}`, style_348);