()
| 372 | } |
| 373 | |
| 374 | watchConfig() { |
| 375 | // Watch the config file for changes |
| 376 | this.configWatcher = fs.watch(this.configPath, (event) => { |
| 377 | if (event === 'change') { |
| 378 | // Clear any existing debounce timer |
| 379 | if (this.debounceTimer) { |
| 380 | clearTimeout(this.debounceTimer); |
| 381 | } |
| 382 | |
| 383 | // Debounce file change events to prevent rapid-fire triggers |
| 384 | this.debounceTimer = setTimeout(() => { |
| 385 | // Ignore changes triggered by our own saves |
| 386 | if (this.isSaving) { |
| 387 | return; |
| 388 | } |
| 389 | |
| 390 | try { |
| 391 | // Read the current file content |
| 392 | const fileContent = fs.readFileSync(this.configPath, 'utf8'); |
| 393 | |
| 394 | // Skip processing if content hasn't actually changed |
| 395 | if (this.lastConfigContent && fileContent === this.lastConfigContent) { |
| 396 | return; |
| 397 | } |
| 398 | |
| 399 | // Store whether this is a new config change (for emitting event later) |
| 400 | const contentChanged = !this.lastConfigContent || fileContent !== this.lastConfigContent; |
| 401 | this.lastConfigContent = fileContent; |
| 402 | |
| 403 | // Load the new config file |
| 404 | this.config = JSON.parse(fileContent); |
| 405 | |
| 406 | // Merge with template to add any new fields |
| 407 | const mergeResult = this.mergeWithTemplate(this.config); |
| 408 | this.config = mergeResult.config; |
| 409 | |
| 410 | // Handle legacy field name (cronSchedule → channelDownloadFrequency) |
| 411 | let legacyMigrationNeeded = false; |
| 412 | if (this.config.cronSchedule && !this.config.channelDownloadFrequency) { |
| 413 | this.config.channelDownloadFrequency = this.config.cronSchedule; |
| 414 | delete this.config.cronSchedule; |
| 415 | legacyMigrationNeeded = true; |
| 416 | } |
| 417 | |
| 418 | // Migrate notification settings to new format |
| 419 | if (this.migrateNotificationSettings()) { |
| 420 | legacyMigrationNeeded = true; |
| 421 | } |
| 422 | |
| 423 | // Save config if modified by merge or legacy migrations |
| 424 | if (mergeResult.modified || legacyMigrationNeeded) { |
| 425 | this.saveConfig(); |
| 426 | } |
| 427 | |
| 428 | // Override temp download settings for Elfhosted platform |
| 429 | if (this.isElfhostedPlatform()) { |
| 430 | this.config.useTmpForDownloads = true; |
| 431 | this.config.tmpFilePath = '/app/config/temp_downloads'; |
no test coverage detected