mirror of
https://github.com/foxhui/WebAI2API.git
synced 2026-06-16 21:03:59 +08:00
feat: 增加拟人鼠标轨迹选择,Token 允许留空 (closes #12)
This commit is contained in:
+13
-4
@@ -231,11 +231,14 @@ export function loadConfig() {
|
||||
if (typeof port !== 'number' || !Number.isInteger(port) || port < 1 || port > 65535) {
|
||||
throw new Error(`server.port 必须是 1-65535 范围内的整数,当前值: ${port}`);
|
||||
}
|
||||
// Auth Token 校验:允许留空,但输出安全警告
|
||||
if (!config.server.auth) {
|
||||
throw new Error('配置文件缺少必需字段: server.auth');
|
||||
}
|
||||
if (typeof config.server.auth !== 'string' || config.server.auth.length < 10) {
|
||||
throw new Error('server.auth 必须是至少 10 个字符的字符串 (建议使用 npm run genkey 生成)');
|
||||
logger.warn('配置器', 'server.auth 未配置!API 和 WebUI 将无需认证即可访问!');
|
||||
logger.warn('配置器', '请勿在公网环境中留空 auth,建议使用 npm run genkey 生成密钥');
|
||||
} else if (config.server.auth === 'sk-change-me-to-your-secure-key') {
|
||||
logger.warn('配置器', '检测到默认密钥!请勿在公网环境中使用默认密钥');
|
||||
} else if (typeof config.server.auth !== 'string' || config.server.auth.length < 10) {
|
||||
logger.warn('配置器', 'server.auth 长度少于 10 个字符,安全性较低,建议使用 npm run genkey 生成密钥');
|
||||
}
|
||||
|
||||
// 设置 keepalive 配置默认值
|
||||
@@ -249,6 +252,12 @@ export function loadConfig() {
|
||||
}
|
||||
}
|
||||
|
||||
// 设置 browser 配置默认值
|
||||
if (!config.browser) config.browser = {};
|
||||
if (config.browser.humanizeCursor === undefined) {
|
||||
config.browser.humanizeCursor = true;
|
||||
}
|
||||
|
||||
// 设置 Pool 配置默认值
|
||||
if (!config.backend) config.backend = {};
|
||||
if (!config.backend.pool) config.backend.pool = {};
|
||||
|
||||
@@ -83,6 +83,7 @@ export function getBrowserConfig() {
|
||||
path: browser.path || '',
|
||||
headless: browser.headless || false,
|
||||
fission: browser.fission !== false, // 默认 true
|
||||
humanizeCursor: browser.humanizeCursor ?? true, // false | true | 'camou'
|
||||
cssInject: {
|
||||
animation: cssInject.animation || false,
|
||||
filter: cssInject.filter || false,
|
||||
@@ -112,6 +113,7 @@ export function saveBrowserConfig(data) {
|
||||
if (data.path !== undefined) config.browser.path = data.path;
|
||||
if (data.headless !== undefined) config.browser.headless = data.headless;
|
||||
if (data.fission !== undefined) config.browser.fission = data.fission;
|
||||
if (data.humanizeCursor !== undefined) config.browser.humanizeCursor = data.humanizeCursor;
|
||||
|
||||
// CSS 性能优化配置
|
||||
if (data.cssInject) {
|
||||
|
||||
@@ -22,12 +22,12 @@ export function validateServerConfig(data) {
|
||||
}
|
||||
}
|
||||
|
||||
// Auth Token 校验
|
||||
// Auth Token 校验:允许留空,但非空时必须至少 10 个字符
|
||||
if (data.authToken !== undefined) {
|
||||
if (typeof data.authToken !== 'string') {
|
||||
errors.push('authToken 必须是字符串');
|
||||
} else if (data.authToken.length < 10) {
|
||||
errors.push('authToken 必须至少 10 个字符');
|
||||
} else if (data.authToken.length > 0 && data.authToken.length < 10) {
|
||||
errors.push('authToken 如果设置则必须至少 10 个字符,或留空');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user