()
| 7 | |
| 8 | class ConfigModule extends EventEmitter { |
| 9 | constructor() { |
| 10 | super(); |
| 11 | this.configPath = path.join(__dirname, '../../config/config.json'); |
| 12 | |
| 13 | // Ensure config exists before attempting to read it |
| 14 | this.ensureConfigExists(); |
| 15 | |
| 16 | this.config = JSON.parse(fs.readFileSync(this.configPath)); |
| 17 | |
| 18 | if (this.isPlatformDeployment()) { |
| 19 | this.ensurePlatformDirectories(); |
| 20 | } |
| 21 | this.task = null; |
| 22 | this.configWatcher = null; |
| 23 | this.debounceTimer = null; |
| 24 | this.isSaving = false; |
| 25 | this.lastConfigContent = null; |
| 26 | |
| 27 | this.directoryPath = ''; |
| 28 | // Allow custom data path via environment variable (for Elfhosted compatibility) |
| 29 | // Falls back to default /usr/src/app/data for backward compatibility |
| 30 | this.directoryPath = process.env.DATA_PATH || '/usr/src/app/data'; |
| 31 | this.ffmpegPath = '/usr/bin/ffmpeg'; |
| 32 | this.atomicParsleyPath = '/usr/bin/AtomicParsley'; |
| 33 | |
| 34 | // Merge with template to add any missing fields |
| 35 | const mergeResult = this.mergeWithTemplate(this.config); |
| 36 | this.config = mergeResult.config; |
| 37 | |
| 38 | // Handle legacy field name (cronSchedule → channelDownloadFrequency) |
| 39 | // This is a one-time migration for old configs |
| 40 | let legacyMigrationNeeded = false; |
| 41 | if (this.config.cronSchedule && !this.config.channelDownloadFrequency) { |
| 42 | this.config.channelDownloadFrequency = this.config.cronSchedule; |
| 43 | delete this.config.cronSchedule; |
| 44 | legacyMigrationNeeded = true; |
| 45 | logger.info('Migrated legacy cronSchedule field to channelDownloadFrequency'); |
| 46 | } |
| 47 | |
| 48 | // Migrate notification settings to new format |
| 49 | if (this.migrateNotificationSettings()) { |
| 50 | legacyMigrationNeeded = true; |
| 51 | } |
| 52 | |
| 53 | // Handle plexPort type conversion (ensure it's a string) |
| 54 | if (this.config.plexPort !== undefined && typeof this.config.plexPort !== 'string') { |
| 55 | this.config.plexPort = String(this.config.plexPort); |
| 56 | legacyMigrationNeeded = true; |
| 57 | logger.info('Converted plexPort to string type'); |
| 58 | } |
| 59 | |
| 60 | // Override temp download settings for Elfhosted platform |
| 61 | if (this.isElfhostedPlatform()) { |
| 62 | this.config.useTmpForDownloads = true; |
| 63 | this.config.tmpFilePath = '/app/config/temp_downloads'; |
| 64 | // Don't save these overrides - they're runtime only |
| 65 | } |
| 66 |
nothing calls this directly
no test coverage detected