(preferredIp, config, preferredPort, preferredUseHttps)
| 14 | constructor() {} |
| 15 | |
| 16 | getBaseUrl(preferredIp, config, preferredPort, preferredUseHttps) { |
| 17 | const resolvedConfig = config || configModule.getConfig(); |
| 18 | const managedUrl = (process.env.PLEX_URL || resolvedConfig.plexUrl || '').trim(); |
| 19 | |
| 20 | if (managedUrl) { |
| 21 | return managedUrl.replace(/\/+$/, ''); |
| 22 | } |
| 23 | |
| 24 | const ip = preferredIp || resolvedConfig.plexIP; |
| 25 | if (!ip) { |
| 26 | return null; |
| 27 | } |
| 28 | |
| 29 | const rawPort = |
| 30 | preferredPort !== undefined && preferredPort !== null && String(preferredPort).trim() !== '' |
| 31 | ? String(preferredPort).trim() |
| 32 | : resolvedConfig.plexPort ?? '32400'; |
| 33 | const numericPort = String(rawPort).replace(/[^0-9]/g, ''); |
| 34 | const port = numericPort || '32400'; |
| 35 | |
| 36 | const useHttps = preferredUseHttps !== undefined ? preferredUseHttps : resolvedConfig.plexViaHttps; |
| 37 | const protocol = useHttps ? 'https' : 'http'; |
| 38 | return `${protocol}://${ip}:${port}`; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Get the Plex library ID that should be refreshed for a given resolved subfolder. |
no test coverage detected