diff --git a/internal/config/types.go b/internal/config/types.go index fb74809..16e4cda 100644 --- a/internal/config/types.go +++ b/internal/config/types.go @@ -35,8 +35,10 @@ type CompressorConfig struct { func (c *Config) UnmarshalJSON(data []byte) error { // 创建一个临时结构来解析原始JSON type TempConfig struct { - MAP map[string]json.RawMessage `json:"MAP"` - Compression CompressionConfig `json:"Compression"` + MAP map[string]json.RawMessage `json:"MAP"` + Compression CompressionConfig `json:"Compression"` + MetricsSaveInterval int `json:"MetricsSaveInterval"` + MetricsMaxFiles int `json:"MetricsMaxFiles"` } var temp TempConfig @@ -47,6 +49,11 @@ func (c *Config) UnmarshalJSON(data []byte) error { // 初始化 MAP c.MAP = make(map[string]PathConfig) + // 复制其他字段 + c.Compression = temp.Compression + c.MetricsSaveInterval = temp.MetricsSaveInterval + c.MetricsMaxFiles = temp.MetricsMaxFiles + // 处理每个路径配置 for key, raw := range temp.MAP { // 尝试作为字符串解析 @@ -69,9 +76,6 @@ func (c *Config) UnmarshalJSON(data []byte) error { c.MAP[key] = pathConfig } - // 复制其他字段 - c.Compression = temp.Compression - return nil } diff --git a/web/app/dashboard/config/page.tsx b/web/app/dashboard/config/page.tsx index b29abff..58205b3 100644 --- a/web/app/dashboard/config/page.tsx +++ b/web/app/dashboard/config/page.tsx @@ -124,6 +124,16 @@ export default function ConfigPage() { } const data = await response.json() + + // 设置默认值 + if (data.MetricsSaveInterval === undefined || data.MetricsSaveInterval === 0) { + data.MetricsSaveInterval = 15; // 默认15分钟 + } + + if (data.MetricsMaxFiles === undefined || data.MetricsMaxFiles === 0) { + data.MetricsMaxFiles = 10; // 默认10个文件 + } + setConfig(data) } catch (error) { const message = error instanceof Error ? error.message : "获取配置失败"