feat: configure max notification items

This commit is contained in:
2026-05-07 00:10:35 +08:00
parent ad48715664
commit 6c8fdc861f
6 changed files with 62 additions and 4 deletions
+7 -2
View File
@@ -34,13 +34,13 @@ export function getNotifyConfig() {
try {
if (!fs.existsSync(NOTIFY_FILE)) return { ...DEFAULT_CONFIG, targetOptions: HERMES_TARGET_OPTIONS };
const cfg = JSON.parse(fs.readFileSync(NOTIFY_FILE, 'utf-8'));
return { ...DEFAULT_CONFIG, ...cfg, targetOptions: HERMES_TARGET_OPTIONS, channels: Array.isArray(cfg.channels) ? cfg.channels : DEFAULT_CONFIG.channels };
return normalizeNotifyConfig({ ...DEFAULT_CONFIG, ...cfg, channels: Array.isArray(cfg.channels) ? cfg.channels : DEFAULT_CONFIG.channels }, true);
} catch {
return { ...DEFAULT_CONFIG, targetOptions: HERMES_TARGET_OPTIONS };
}
}
export function saveNotifyConfig(config = {}) {
function normalizeNotifyConfig(config = {}, includeTargetOptions = false) {
const normalized = {
enabled: config.enabled !== false,
notifyOnlyGood: config.notifyOnlyGood !== false,
@@ -57,6 +57,11 @@ export function saveNotifyConfig(config = {}) {
target: c.target || c.platform || 'feishu',
})),
};
return includeTargetOptions ? { ...normalized, targetOptions: HERMES_TARGET_OPTIONS } : normalized;
}
export function saveNotifyConfig(config = {}) {
const normalized = normalizeNotifyConfig(config);
fs.mkdirSync(DATA_DIR, { recursive: true });
fs.writeFileSync(NOTIFY_FILE, JSON.stringify(normalized, null, 2), 'utf-8');
return { ...normalized, targetOptions: HERMES_TARGET_OPTIONS };