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:
parent
1bc193f5eb
commit
df9a36291c
2 changed files with 17 additions and 2 deletions
|
|
@ -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;
|
if (newConfig.LOG_MAX_FILES !== undefined) currentConfig.LOG_MAX_FILES = newConfig.LOG_MAX_FILES;
|
||||||
|
|
||||||
// Scheduled Health Check settings
|
// 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
|
// Handle system prompt update
|
||||||
if (newConfig.systemPrompt !== undefined) {
|
if (newConfig.systemPrompt !== undefined) {
|
||||||
|
|
|
||||||
|
|
@ -398,10 +398,14 @@ async function saveConfiguration() {
|
||||||
.map(tag => tag.getAttribute('data-value'))
|
.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 = {
|
config.SCHEDULED_HEALTH_CHECK = {
|
||||||
enabled: document.getElementById('scheduledHealthCheckEnabled')?.checked !== false,
|
enabled: document.getElementById('scheduledHealthCheckEnabled')?.checked !== false,
|
||||||
startupRun: document.getElementById('scheduledHealthCheckStartupRun')?.checked !== false,
|
startupRun: document.getElementById('scheduledHealthCheckStartupRun')?.checked !== false,
|
||||||
interval: parseInt(document.getElementById('scheduledHealthCheckInterval')?.value || 600000),
|
interval: validatedInterval,
|
||||||
providerTypes: scheduledHealthCheckProviderTypes
|
providerTypes: scheduledHealthCheckProviderTypes
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue