fix: abort availability sync job if auth token invalid/connection lost (#845)

This fix aborts the media availability sync job if the following conditions are met:
a) auth token has expired
b) connection to jellyfin/emby has been lost
Previously, the sync job will continue even if auth token was invalid or
connection was lost, thereby, resulting in removal of series/movies that
were never removed on jellyfin/emby/sonarr/radarr. This also removed the
requests. With the current fix, the sync job should refuse to run unless
the auth token is valid.
This commit is contained in:
Fallenbagel
2024-06-29 19:10:43 +05:00
committed by GitHub
parent 96ba53fecc
commit bdee340530

View File

@@ -73,16 +73,16 @@ class AvailabilitySync {
}); });
} }
if (mediaServerType === MediaServerType.PLEX) { switch (mediaServerType) {
case MediaServerType.PLEX:
if (admin && admin.plexToken) { if (admin && admin.plexToken) {
this.plexClient = new PlexAPI({ plexToken: admin.plexToken }); this.plexClient = new PlexAPI({ plexToken: admin.plexToken });
} else { } else {
logger.error('Plex admin is not configured.'); logger.error('Plex admin is not configured.');
} }
} else if ( break;
mediaServerType === MediaServerType.JELLYFIN || case MediaServerType.JELLYFIN:
mediaServerType === MediaServerType.EMBY case MediaServerType.EMBY:
) {
if (admin) { if (admin) {
this.jellyfinClient = new JellyfinAPI( this.jellyfinClient = new JellyfinAPI(
getHostname(), getHostname(),
@@ -91,11 +91,32 @@ class AvailabilitySync {
); );
this.jellyfinClient.setUserId(admin.jellyfinUserId ?? ''); this.jellyfinClient.setUserId(admin.jellyfinUserId ?? '');
} else {
logger.error('Jellyfin admin is not configured.'); try {
await this.jellyfinClient.getSystemInfo();
} catch (e) {
logger.error('Sync interrupted.', {
label: 'AvailabilitySync',
status: e.statusCode,
error: e.name,
errorMessage: e.errorCode,
});
this.running = false;
return;
} }
} else { } else {
logger.error('Jellyfin admin is not configured.');
this.running = false;
return;
}
break;
default:
logger.error('An admin is not configured.'); logger.error('An admin is not configured.');
this.running = false;
return;
} }
for await (const media of this.loadAvailableMediaPaginated(pageSize)) { for await (const media of this.loadAvailableMediaPaginated(pageSize)) {