diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..526c8a38 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.sh text eol=lf \ No newline at end of file diff --git a/server/src/modules/api/servarr-api/helpers/sonarr.helper.ts b/server/src/modules/api/servarr-api/helpers/sonarr.helper.ts index 60218d55..8e4d1983 100644 --- a/server/src/modules/api/servarr-api/helpers/sonarr.helper.ts +++ b/server/src/modules/api/servarr-api/helpers/sonarr.helper.ts @@ -370,6 +370,13 @@ export class SonarrApi extends ServarrApi<{ } } } + + this.logger.log( + `Unmonitored ${ + typeof type === 'number' ? `season ${type}` : 'seasons' + } from Sonarr show with ID ${seriesId}`, + ); + return data; } catch (e) { this.logger.log("Couldn't unmonitor/delete. Does it exist in sonarr?", { @@ -379,11 +386,6 @@ export class SonarrApi extends ServarrApi<{ }); this.logger.debug(e); } - this.logger.log( - `Unmonitored ${ - typeof type === 'number' ? `season ${type}` : 'seasons' - } from Sonarr show with ID ${seriesId}`, - ); } private buildSeasonList( diff --git a/server/src/modules/api/servarr-api/servarr.service.ts b/server/src/modules/api/servarr-api/servarr.service.ts index 5c908a96..02ba2a3c 100644 --- a/server/src/modules/api/servarr-api/servarr.service.ts +++ b/server/src/modules/api/servarr-api/servarr.service.ts @@ -9,8 +9,8 @@ import { SonarrSettingRawDto } from "../../settings/dto's/sonarr-setting.dto"; @Injectable() export class ServarrService { SonarrApi: SonarrApi; - private radarrApiCache?: Record = {}; - private sonarrApiCache?: Record = {}; + private radarrApiCache: Record = {}; + private sonarrApiCache: Record = {}; constructor( @Inject(forwardRef(() => SettingsService)) @@ -27,7 +27,7 @@ export class ServarrService { if (!this.sonarrApiCache[id]) { const setting = await this.settings.getSonarrSetting(id); - if (!('id' in setting)) { + if (setting == null || !('id' in setting)) { throw new Error('Sonarr setting not found'); } @@ -57,7 +57,7 @@ export class ServarrService { if (!this.radarrApiCache[id]) { const setting = await this.settings.getRadarrSetting(id); - if (!('id' in setting)) { + if (setting == null || !('id' in setting)) { throw new Error('Radarr setting not found'); } diff --git a/server/src/modules/collections/collection-worker.service.ts b/server/src/modules/collections/collection-worker.service.ts index 8ec02883..d571def2 100644 --- a/server/src/modules/collections/collection-worker.service.ts +++ b/server/src/modules/collections/collection-worker.service.ts @@ -143,12 +143,12 @@ export class CollectionWorkerService extends TaskBase { this.collectionService.saveCollection(collection); - const radarrApiClient = collection.radarrSettings.id - ? await this.servarrApi.getRadarrApiClient(collection.radarrSettings.id) + const radarrApiClient = collection.radarrSettingsId + ? await this.servarrApi.getRadarrApiClient(collection.radarrSettingsId) : undefined; - const sonarrApiClient = collection.sonarrSettings.id - ? await this.servarrApi.getSonarrApiClient(collection.sonarrSettings.id) + const sonarrApiClient = collection.sonarrSettingsId + ? await this.servarrApi.getSonarrApiClient(collection.sonarrSettingsId) : undefined; if (plexLibrary.type === 'movie') { @@ -256,7 +256,7 @@ export class CollectionWorkerService extends TaskBase { if (tvdbId) { let sonarrMedia = await sonarrApiClient.getSeriesByTvdbId(tvdbId); - if (sonarrMedia) { + if (sonarrMedia?.id) { switch (collection.arrAction) { case ServarrAction.DELETE: switch (collection.type) { @@ -322,12 +322,16 @@ export class CollectionWorkerService extends TaskBase { 'all', false, ); - // unmonitor show - sonarrMedia.monitored = false; - sonarrApiClient.updateSeries(sonarrMedia); - this.infoLogger( - `[Sonarr] Unmonitored show '${sonarrMedia.title}'`, - ); + + if (sonarrMedia) { + // unmonitor show + sonarrMedia.monitored = false; + sonarrApiClient.updateSeries(sonarrMedia); + this.infoLogger( + `[Sonarr] Unmonitored show '${sonarrMedia.title}'`, + ); + } + break; } break; @@ -360,12 +364,16 @@ export class CollectionWorkerService extends TaskBase { 'all', true, ); - // unmonitor show - sonarrMedia.monitored = false; - sonarrApiClient.updateSeries(sonarrMedia); - this.infoLogger( - `[Sonarr] Unmonitored show '${sonarrMedia.title}' and removed all episodes`, - ); + + if (sonarrMedia) { + // unmonitor show + sonarrMedia.monitored = false; + sonarrApiClient.updateSeries(sonarrMedia); + this.infoLogger( + `[Sonarr] Unmonitored show '${sonarrMedia.title}' and removed all episodes`, + ); + } + break; } break; @@ -399,12 +407,16 @@ export class CollectionWorkerService extends TaskBase { 'existing', true, ); - // unmonitor show - sonarrMedia.monitored = false; - sonarrApiClient.updateSeries(sonarrMedia); - this.infoLogger( - `[Sonarr] Unmonitored show '${sonarrMedia.title}' and Removed exisiting episodes`, - ); + + if (sonarrMedia) { + // unmonitor show + sonarrMedia.monitored = false; + sonarrApiClient.updateSeries(sonarrMedia); + this.infoLogger( + `[Sonarr] Unmonitored show '${sonarrMedia.title}' and Removed exisiting episodes`, + ); + } + break; } break;