(libraryId)
| 72 | } |
| 73 | |
| 74 | async refreshLibrary(libraryId) { |
| 75 | const config = configModule.getConfig(); |
| 76 | const resolvedLibraryId = libraryId || config.plexYoutubeLibraryId; |
| 77 | try { |
| 78 | const baseUrl = this.getBaseUrl(config.plexIP, config, config.plexPort, config.plexViaHttps); |
| 79 | |
| 80 | if (!baseUrl || !resolvedLibraryId || !config.plexApiKey) { |
| 81 | logger.warn('Skipping Plex refresh - missing server details or credentials'); |
| 82 | return null; |
| 83 | } |
| 84 | |
| 85 | if (!/^\d+$/.test(String(resolvedLibraryId))) { |
| 86 | logger.warn({ libraryId: resolvedLibraryId }, 'Skipping Plex refresh - invalid non-numeric library ID'); |
| 87 | return null; |
| 88 | } |
| 89 | |
| 90 | logger.info({ libraryId: resolvedLibraryId }, 'Refreshing Plex library'); |
| 91 | const response = await axios.get( |
| 92 | `${baseUrl}/library/sections/${encodeURIComponent(resolvedLibraryId)}/refresh?X-Plex-Token=${config.plexApiKey}`, |
| 93 | { timeout: PLEX_REQUEST_TIMEOUT_MS } |
| 94 | ); |
| 95 | logger.info({ libraryId: resolvedLibraryId }, 'Plex library refresh initiated successfully'); |
| 96 | return response; |
| 97 | } catch (error) { |
| 98 | logger.error({ err: error }, 'Failed to refresh Plex library'); |
| 99 | if (error.code === 'ECONNREFUSED') { |
| 100 | logger.warn('Could not connect to Plex server - continuing without refresh'); |
| 101 | } else if (error.code === 'ECONNABORTED') { |
| 102 | logger.warn('Plex request timed out - continuing without refresh'); |
| 103 | } |
| 104 | // Return null or empty response to indicate failure, but don't throw |
| 105 | return null; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | async getLibraries() { |
| 110 | const config = configModule.getConfig(); |
no test coverage detected