Merge branch 'bugfix_ip_address' into develop

This commit is contained in:
Sakamoto Shiina
2025-03-22 17:31:20 +09:00
5 changed files with 53 additions and 27 deletions

View File

@@ -6,7 +6,7 @@ import re
from device_manager import device_manager from device_manager import device_manager
from config import config from config import config
from model import model from model import model
from utils import removeLog, printLog, errorLogging, isConnectedNetwork from utils import removeLog, printLog, errorLogging, isConnectedNetwork, isValidIpAddress
class Controller: class Controller:
def __init__(self) -> None: def __init__(self) -> None:
@@ -1085,9 +1085,29 @@ class Controller:
@staticmethod @staticmethod
def setOscIpAddress(data, *args, **kwargs) -> dict: def setOscIpAddress(data, *args, **kwargs) -> dict:
config.OSC_IP_ADDRESS = data if isValidIpAddress(data) is False:
model.setOscIpAddress(config.OSC_IP_ADDRESS) response = {
return {"status":200, "result":config.OSC_IP_ADDRESS} "status":400,
"result":{
"message":"Invalid IP address",
"data": config.OSC_IP_ADDRESS
}
}
else:
try:
model.setOscIpAddress(data)
config.OSC_IP_ADDRESS = data
response = {"status":200, "result":config.OSC_IP_ADDRESS}
except Exception:
model.setOscIpAddress(config.OSC_IP_ADDRESS)
response = {
"status":400,
"result":{
"message":"Cannot set IP address",
"data": config.OSC_IP_ADDRESS
}
}
return response
@staticmethod @staticmethod
def getOscPort(*args, **kwargs) -> dict: def getOscPort(*args, **kwargs) -> dict:

View File

@@ -7,14 +7,22 @@ from logging.handlers import RotatingFileHandler
from ctranslate2 import get_supported_compute_types from ctranslate2 import get_supported_compute_types
import requests import requests
import ipaddress
def isConnectedNetwork(url="http://www.google.com", timeout=3): def isConnectedNetwork(url="http://www.google.com", timeout=3) -> bool:
try: try:
response = requests.get(url, timeout=timeout) response = requests.get(url, timeout=timeout)
return response.status_code == 200 return response.status_code == 200
except requests.RequestException: except requests.RequestException:
return False 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: def getBestComputeType(device, device_index) -> str:
compute_types = get_supported_compute_types(device, device_index) compute_types = get_supported_compute_types(device, device_index)
compute_types = set(compute_types) compute_types = set(compute_types)

View File

@@ -15,9 +15,7 @@ import {
useDeepLAuthKey, useDeepLAuthKey,
useOscIpAddress, useOscIpAddress,
useOscPort,
} from "@logics_configs"; } from "@logics_configs";
import { ui_configs } from "../ui_configs"; import { ui_configs } from "../ui_configs";
@@ -35,9 +33,7 @@ export const _useBackendErrorHandling = () => {
const { updateDeepLAuthKey, saveErrorDeepLAuthKey } = useDeepLAuthKey(); const { updateDeepLAuthKey, saveErrorDeepLAuthKey } = useDeepLAuthKey();
const { updateOscIpAddress } = useOscIpAddress();
const { saveErrorOscIpAddress } = useOscIpAddress();
const { saveErrorOscPort } = useOscPort();
const errorHandling_Backend = ({message, data, endpoint, _result}) => { const errorHandling_Backend = ({message, data, endpoint, _result}) => {
switch (message) { switch (message) {
@@ -55,9 +51,9 @@ export const _useBackendErrorHandling = () => {
break; break;
case "Speaker energy threshold value is out of range": case "Speaker energy threshold value is out of range":
showNotification_Error(t("common_error.threshold_invalid_value", showNotification_Error(t("common_error.threshold_invalid_value",
{ min: ui_configs.speaker_threshold_min, max: ui_configs.speaker_threshold_max }, { min: ui_configs.speaker_threshold_min, max: ui_configs.speaker_threshold_max },
)); ));
break; break;
case "CTranslate2 weight download error": case "CTranslate2 weight download error":
showNotification_Error(t("common_error.failed_download_weight_ctranslate2")); 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")); showNotification_Error(t("common_error.invalid_value_speaker_max_phrase"));
break; 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: default:
// determine by endpoint, not message. // determine by endpoint, not message.
if (endpoint === "/set/data/deepl_auth_key") saveErrorDeepLAuthKey({message, data, endpoint, _result}); 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; break;
} }

View File

@@ -1,9 +1,7 @@
import { useStore_OscIpAddress } from "@store"; import { useStore_OscIpAddress } from "@store";
import { useStdoutToPython } from "@logics/useStdoutToPython"; import { useStdoutToPython } from "@logics/useStdoutToPython";
import { useNotificationStatus } from "@logics_common";
export const useOscIpAddress = () => { export const useOscIpAddress = () => {
const { showNotification_Error } = useNotificationStatus();
const { asyncStdoutToPython } = useStdoutToPython(); const { asyncStdoutToPython } = useStdoutToPython();
const { currentOscIpAddress, updateOscIpAddress, pendingOscIpAddress } = useStore_OscIpAddress(); const { currentOscIpAddress, updateOscIpAddress, pendingOscIpAddress } = useStore_OscIpAddress();
@@ -17,17 +15,10 @@ export const useOscIpAddress = () => {
asyncStdoutToPython("/set/data/osc_ip_address", osc_ip_address); asyncStdoutToPython("/set/data/osc_ip_address", osc_ip_address);
}; };
const saveErrorOscIpAddress = ({data, message, _result}) => {
updateOscIpAddress(d => d.data);
showNotification_Error(_result);
};
return { return {
currentOscIpAddress, currentOscIpAddress,
getOscIpAddress, getOscIpAddress,
updateOscIpAddress, updateOscIpAddress,
setOscIpAddress, setOscIpAddress,
saveErrorOscIpAddress,
}; };
}; };

View File

@@ -525,7 +525,6 @@ export const useReceiveRoutes = () => {
"/set/data/speaker_max_phrases": errorHandling_Backend, "/set/data/speaker_max_phrases": errorHandling_Backend,
"/set/data/osc_ip_address": errorHandling_Backend, "/set/data/osc_ip_address": errorHandling_Backend,
"/set/data/osc_port": errorHandling_Backend,
}; };
@@ -558,7 +557,6 @@ export const useReceiveRoutes = () => {
break; break;
case 400: case 400:
case 500:
const error_route = error_status_routes[parsed_data.endpoint]; const error_route = error_status_routes[parsed_data.endpoint];
if (error_route) { if (error_route) {
error_route({ error_route({
@@ -571,6 +569,10 @@ export const useReceiveRoutes = () => {
handleInvalidEndpoint(parsed_data); handleInvalidEndpoint(parsed_data);
} }
break; 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: case 348:
// console.log(`from backend: %c ${JSON.stringify(parsed_data)}`, style_348); // console.log(`from backend: %c ${JSON.stringify(parsed_data)}`, style_348);