refactor: cleaned up code and added more detail to logs

pull/3460/head
Brandon Cohen 1 year ago committed by OwsleyJr
parent 1cb691f9cd
commit 8d96c0ce53

@ -3,7 +3,7 @@ import PlexAPI from '@server/api/plexapi';
import RadarrAPI, { type RadarrMovie } from '@server/api/servarr/radarr';
import type { SonarrSeason, SonarrSeries } from '@server/api/servarr/sonarr';
import SonarrAPI from '@server/api/servarr/sonarr';
import { MediaStatus } from '@server/constants/media';
import { MediaRequestStatus, MediaStatus } from '@server/constants/media';
import { getRepository } from '@server/datasource';
import Media from '@server/entity/Media';
import MediaRequest from '@server/entity/MediaRequest';
@ -203,8 +203,8 @@ class AvailabilitySync {
await this.mediaUpdater(media, true);
}
}
if (!mediaExists || didDeleteSeasons) {
await mediaRepository.save(media);
if (!mediaExists) {
await mediaRepository.save({ media, ...media });
}
}
} catch (ex) {
@ -487,6 +487,14 @@ class AvailabilitySync {
}
}
if ((!radarr || !radarr.hasFile) && !existsInPlex) {
movieExists = false;
}
if ((!radarr4k || !radarr4k.hasFile) && !existsInPlex4k) {
movieExists4k = false;
}
return existsInRadarr;
}
@ -540,6 +548,25 @@ class AvailabilitySync {
}
}
if (
(!sonarr || sonarr.statistics.episodeFileCount === 0) &&
!existsInPlex
) {
showExists = false;
}
if (
(!sonarr4k || sonarr4k.statistics.episodeFileCount === 0) &&
!existsInPlex4k
) {
showExists4k = false;
}
// Here we check each season for availability
for (const season of media.seasons) {
await this.seasonExists(media, season, showExists, showExists4k);
}
// Here we check each season for availability
// If the API returns an error other than a 404,
// we will have to prevent the season check from happening

@ -40,7 +40,6 @@ requestRoutes.get<Record<string, unknown>, RequestResultsResponse>(
switch (req.query.filter) {
case 'approved':
case 'processing':
case 'available':
statusFilter = [MediaRequestStatus.APPROVED];
break;
case 'pending':
@ -56,6 +55,7 @@ requestRoutes.get<Record<string, unknown>, RequestResultsResponse>(
statusFilter = [MediaRequestStatus.FAILED];
break;
case 'completed':
case 'available':
case 'deleted':
statusFilter = [MediaRequestStatus.COMPLETED];
break;

Loading…
Cancel
Save