mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-28 01:53:53 +08:00
添加新的参数:声纹接口地址
--202507031602.sql 添加声纹接口地址参数sql --Constant.java 对应新参数的常量 --SysParamsController.java 验证声纹接口地址参数是否符合规则 --db.changelog-master.yaml 添加执行新的sql文件
This commit is contained in:
@@ -116,6 +116,11 @@ public interface Constant {
|
|||||||
*/
|
*/
|
||||||
String SERVER_MCP_ENDPOINT = "server.mcp_endpoint";
|
String SERVER_MCP_ENDPOINT = "server.mcp_endpoint";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mcp接入点路径
|
||||||
|
*/
|
||||||
|
String SERVER_VOICE_PRINT = "server.voice_print";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 无记忆
|
* 无记忆
|
||||||
*/
|
*/
|
||||||
|
|||||||
+37
@@ -107,6 +107,9 @@ public class SysParamsController {
|
|||||||
// 验证MCP地址
|
// 验证MCP地址
|
||||||
validateMcpUrl(dto.getParamCode(), dto.getParamValue());
|
validateMcpUrl(dto.getParamCode(), dto.getParamValue());
|
||||||
|
|
||||||
|
//
|
||||||
|
validateVoicePrint(dto.getParamCode(), dto.getParamValue());
|
||||||
|
|
||||||
sysParamsService.update(dto);
|
sysParamsService.update(dto);
|
||||||
configService.getConfig(false);
|
configService.getConfig(false);
|
||||||
return new Result<Void>();
|
return new Result<Void>();
|
||||||
@@ -212,6 +215,7 @@ public class SysParamsController {
|
|||||||
if (!url.toLowerCase().contains("key")) {
|
if (!url.toLowerCase().contains("key")) {
|
||||||
throw new RenException("不是正确的MCP地址");
|
throw new RenException("不是正确的MCP地址");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 发送GET请求
|
// 发送GET请求
|
||||||
ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);
|
ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);
|
||||||
@@ -227,4 +231,37 @@ public class SysParamsController {
|
|||||||
throw new RenException("MCP接口验证失败:" + e.getMessage());
|
throw new RenException("MCP接口验证失败:" + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 验证声纹接口地址是否正常
|
||||||
|
private void validateVoicePrint(String paramCode, String url) {
|
||||||
|
if (!paramCode.equals(Constant.SERVER_VOICE_PRINT)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (StringUtils.isBlank(url) || url.equals("null")) {
|
||||||
|
throw new RenException("声纹接口地址不能为空");
|
||||||
|
}
|
||||||
|
if (url.contains("localhost") || url.contains("127.0.0.1")) {
|
||||||
|
throw new RenException("声纹接口地址不能使用localhost或127.0.0.1");
|
||||||
|
}
|
||||||
|
if (!url.toLowerCase().contains("key")) {
|
||||||
|
throw new RenException("不是正确的声纹接口地址");
|
||||||
|
}
|
||||||
|
// 验证URL格式
|
||||||
|
if (!url.toLowerCase().startsWith("http")) {
|
||||||
|
throw new RenException("声纹接口地址必须以http或https开头");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
// 发送GET请求
|
||||||
|
ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);
|
||||||
|
if (response.getStatusCode() != HttpStatus.OK) {
|
||||||
|
throw new RenException("声纹接口访问失败,状态码:" + response.getStatusCode());
|
||||||
|
}
|
||||||
|
// 检查响应内容
|
||||||
|
String body = response.getBody();
|
||||||
|
if (body == null || !body.contains("healthy")) {
|
||||||
|
throw new RenException("声纹接口返回内容格式不正确,可能不是一个真实的MCP接口");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RenException("声纹接口验证失败:" + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
-- 添加声纹接口地址参数配置
|
||||||
|
delete from `sys_params` where id = 114;
|
||||||
|
INSERT INTO `sys_params` (id, param_code, param_value, value_type, param_type, remark)
|
||||||
|
VALUES (114, 'server.voice_print', 'null', 'string', 1, '声纹接口地址');
|
||||||
@@ -239,4 +239,11 @@ databaseChangeLog:
|
|||||||
changes:
|
changes:
|
||||||
- sqlFile:
|
- sqlFile:
|
||||||
encoding: utf8
|
encoding: utf8
|
||||||
path: classpath:db/changelog/202506261637.sql
|
path: classpath:db/changelog/202506261637.sql
|
||||||
|
- changeSet:
|
||||||
|
id: 202507031602
|
||||||
|
author: zjy
|
||||||
|
changes:
|
||||||
|
- sqlFile:
|
||||||
|
encoding: utf8
|
||||||
|
path: classpath:db/changelog/202507031602.sql
|
||||||
Reference in New Issue
Block a user