fix: 添加配置验证防止格式错误的数据

1. config-api.js: 添加 SCHEDULED_HEALTH_CHECK 结构验证

2. config-manager.js: 添加 interval 值范围验证 (60000-3600000ms)

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
Wenaixi 2026-03-30 23:41:49 +08:00
parent 1bc193f5eb
commit df9a36291c
2 changed files with 17 additions and 2 deletions

View file

@ -116,7 +116,18 @@ export async function handleUpdateConfig(req, res, currentConfig) {
if (newConfig.LOG_MAX_FILES !== undefined) currentConfig.LOG_MAX_FILES = newConfig.LOG_MAX_FILES;
// Scheduled Health Check settings
if (newConfig.SCHEDULED_HEALTH_CHECK !== undefined) currentConfig.SCHEDULED_HEALTH_CHECK = newConfig.SCHEDULED_HEALTH_CHECK;
if (newConfig.SCHEDULED_HEALTH_CHECK !== undefined) {
const incoming = newConfig.SCHEDULED_HEALTH_CHECK;
currentConfig.SCHEDULED_HEALTH_CHECK = {
enabled: incoming?.enabled === true,
startupRun: incoming?.startupRun !== false,
interval: (() => {
const val = Number(incoming?.interval);
return isNaN(val) ? 600000 : Math.max(60000, Math.min(3600000, val));
})(),
providerTypes: Array.isArray(incoming?.providerTypes) ? incoming.providerTypes : []
};
}
// Handle system prompt update
if (newConfig.systemPrompt !== undefined) {

View file

@ -398,10 +398,14 @@ async function saveConfiguration() {
.map(tag => tag.getAttribute('data-value'))
: [];
// 验证并规范化 interval 值
const rawInterval = parseInt(document.getElementById('scheduledHealthCheckInterval')?.value);
const validatedInterval = isNaN(rawInterval) ? 600000 : Math.max(60000, Math.min(3600000, rawInterval));
config.SCHEDULED_HEALTH_CHECK = {
enabled: document.getElementById('scheduledHealthCheckEnabled')?.checked !== false,
startupRun: document.getElementById('scheduledHealthCheckStartupRun')?.checked !== false,
interval: parseInt(document.getElementById('scheduledHealthCheckInterval')?.value || 600000),
interval: validatedInterval,
providerTypes: scheduledHealthCheckProviderTypes
};