Skip to content

Commit

Permalink
refactor: concistency
Browse files Browse the repository at this point in the history
  • Loading branch information
bonswouar committed Nov 11, 2024
1 parent 206582d commit 7e9d84d
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 63 deletions.
2 changes: 1 addition & 1 deletion cypress/config/settings.cypress.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"trustProxy": false,
"mediaServerType": 1,
"partialRequestsEnabled": true,
"removeUnmonitoredFromRequestsEnabled": false,
"removeUnmonitoredEnabled": false,
"locale": "en"
},
"plex": {
Expand Down
2 changes: 1 addition & 1 deletion overseerr-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ components:
partialRequestsEnabled:
type: boolean
example: false
removeUnmonitoredFromRequestsEnabled:
removeUnmonitoredEnabled:
type: boolean
example: false
localLogin:
Expand Down
2 changes: 1 addition & 1 deletion server/interfaces/api/settingsInterfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export interface PublicSettingsResponse {
originalLanguage: string;
mediaServerType: number;
partialRequestsEnabled: boolean;
removeUnmonitoredFromRequestsEnabled: boolean;
removeUnmonitoredEnabled: boolean;
cacheImages: boolean;
vapidPublic: string;
enablePushRegistration: boolean;
Expand Down
50 changes: 45 additions & 5 deletions server/lib/scanners/baseScanner.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import type { SonarrSeason } from '@server/api/servarr/sonarr';
import TheMovieDb from '@server/api/themoviedb';
import { MediaStatus, MediaType } from '@server/constants/media';
import { getRepository } from '@server/datasource';
import Media from '@server/entity/Media';
import { MediaRequest } from '@server/entity/MediaRequest';
import Season from '@server/entity/Season';
import SeasonRequest from '@server/entity/SeasonRequest';
import { getSettings } from '@server/lib/settings';
import logger from '@server/logger';
import AsyncLock from '@server/utils/asyncLock';
Expand Down Expand Up @@ -212,7 +215,7 @@ class BaseScanner<T> {

/**
* processShow takes a TMDB ID and an array of ProcessableSeasons, which
* should include the total episodes a sesaon has + the total available
* should include the total episodes a season has + the total available
* episodes that each season currently has. Unlike processMovie, this method
* does not take an `is4k` option. We handle both the 4k _and_ non 4k status
* in one method.
Expand Down Expand Up @@ -279,13 +282,14 @@ class BaseScanner<T> {
// force it to stay available (to avoid competing scanners)
existingSeason.status =
(season.totalEpisodes === season.episodes && season.episodes > 0) ||
existingSeason.status === MediaStatus.AVAILABLE
(existingSeason.status === MediaStatus.AVAILABLE &&
season.episodes > 0)
? MediaStatus.AVAILABLE
: season.episodes > 0
? MediaStatus.PARTIALLY_AVAILABLE
: !season.is4kOverride && season.processing
? MediaStatus.PROCESSING
: settings.main.removeUnmonitoredFromRequestsEnabled &&
: settings.main.removeUnmonitoredEnabled &&
!season.monitored &&
season.episodes == 0
? MediaStatus.UNKNOWN
Expand All @@ -296,13 +300,14 @@ class BaseScanner<T> {
(this.enable4kShow &&
season.episodes4k === season.totalEpisodes &&
season.episodes4k > 0) ||
existingSeason.status4k === MediaStatus.AVAILABLE
(existingSeason.status4k === MediaStatus.AVAILABLE &&
season.episodes > 0)
? MediaStatus.AVAILABLE
: this.enable4kShow && season.episodes4k > 0
? MediaStatus.PARTIALLY_AVAILABLE
: season.is4kOverride && season.processing
? MediaStatus.PROCESSING
: settings.main.removeUnmonitoredFromRequestsEnabled &&
: settings.main.removeUnmonitoredEnabled &&
!season.monitored &&
season.episodes4k == 0
? MediaStatus.UNKNOWN
Expand Down Expand Up @@ -643,6 +648,41 @@ class BaseScanner<T> {
}
});
}

protected async processUnmonitoredSeason(
tmdbId: number,
season: SonarrSeason
): Promise<void> {
// Remove unmonitored seasons from Requests
const requestRepository = getRepository(MediaRequest);
const seasonRequestRepository = getRepository(SeasonRequest);

const existingRequests = await requestRepository
.createQueryBuilder('request')
.innerJoinAndSelect('request.media', 'media')
.innerJoinAndSelect('request.seasons', 'seasons')
.where('media.tmdbId = :tmdbId', { tmdbId: tmdbId })
.andWhere('media.mediaType = :mediaType', {
mediaType: MediaType.TV,
})
.andWhere('seasons.seasonNumber = :seasonNumber', {
seasonNumber: season.seasonNumber,
})
.getMany();

if (existingRequests && existingRequests.length > 0) {
existingRequests.forEach((existingRequest) => {
existingRequest.seasons.forEach(async (requestedSeason) => {
if (requestedSeason.seasonNumber === season.seasonNumber) {
this.log(
`Removing request for Season ${season.seasonNumber} of tmdbId ${tmdbId} as it is unmonitored`
);
await seasonRequestRepository.remove(requestedSeason);
}
});
});
}
}
}

export default BaseScanner;
2 changes: 1 addition & 1 deletion server/lib/scanners/radarr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class RadarrScanner
private async processRadarrMovie(radarrMovie: RadarrMovie): Promise<void> {
const settings = getSettings();
if (
settings.main.removeUnmonitoredFromRequestsEnabled &&
settings.main.removeUnmonitoredEnabled &&
!radarrMovie.monitored &&
!radarrMovie.hasFile
) {
Expand Down
35 changes: 2 additions & 33 deletions server/lib/scanners/sonarr/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import type { SonarrSeries } from '@server/api/servarr/sonarr';
import SonarrAPI from '@server/api/servarr/sonarr';
import type { TmdbTvDetails } from '@server/api/themoviedb/interfaces';
import { MediaType } from '@server/constants/media';
import { getRepository } from '@server/datasource';
import Media from '@server/entity/Media';
import { MediaRequest } from '@server/entity/MediaRequest';
import SeasonRequest from '@server/entity/SeasonRequest';
import type {
ProcessableSeason,
RunnableScanner,
Expand Down Expand Up @@ -117,39 +114,11 @@ class SonarrScanner
const totalAvailableEpisodes = season.statistics?.episodeFileCount ?? 0;

if (
settings.main.removeUnmonitoredFromRequestsEnabled &&
settings.main.removeUnmonitoredEnabled &&
season.monitored === false &&
totalAvailableEpisodes === 0
) {
// Remove unmonitored seasons from Requests
const requestRepository = getRepository(MediaRequest);
const seasonRequestRepository = getRepository(SeasonRequest);

const existingRequests = await requestRepository
.createQueryBuilder('request')
.innerJoinAndSelect('request.media', 'media')
.innerJoinAndSelect('request.seasons', 'seasons')
.where('media.tmdbId = :tmdbId', { tmdbId: tmdbId })
.andWhere('media.mediaType = :mediaType', {
mediaType: MediaType.TV,
})
.andWhere('seasons.seasonNumber = :seasonNumber', {
seasonNumber: season.seasonNumber,
})
.getMany();

if (existingRequests && existingRequests.length > 0) {
existingRequests.forEach((existingRequest) => {
existingRequest.seasons.forEach(async (requestedSeason) => {
if (requestedSeason.seasonNumber === season.seasonNumber) {
this.log(
`Removing request for Season ${season.seasonNumber} of ${sonarrSeries.title} as it is unmonitored`
);
await seasonRequestRepository.remove(requestedSeason);
}
});
});
}
this.processUnmonitoredSeason(tmdbId, season);
}

processableSeasons.push({
Expand Down
9 changes: 4 additions & 5 deletions server/lib/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export interface MainSettings {
trustProxy: boolean;
mediaServerType: number;
partialRequestsEnabled: boolean;
removeUnmonitoredFromRequestsEnabled: boolean;
removeUnmonitoredEnabled: boolean;
locale: string;
proxy: ProxySettings;
}
Expand All @@ -152,7 +152,7 @@ interface FullPublicSettings extends PublicSettings {
jellyfinForgotPasswordUrl?: string;
jellyfinServerName?: string;
partialRequestsEnabled: boolean;
removeUnmonitoredFromRequestsEnabled: boolean;
removeUnmonitoredEnabled: boolean;
cacheImages: boolean;
vapidPublic: string;
enablePushRegistration: boolean;
Expand Down Expand Up @@ -338,7 +338,7 @@ class Settings {
trustProxy: false,
mediaServerType: MediaServerType.NOT_CONFIGURED,
partialRequestsEnabled: true,
removeUnmonitoredFromRequestsEnabled: false,
removeUnmonitoredEnabled: false,
locale: 'en',
proxy: {
enabled: false,
Expand Down Expand Up @@ -577,8 +577,7 @@ class Settings {
originalLanguage: this.data.main.originalLanguage,
mediaServerType: this.main.mediaServerType,
partialRequestsEnabled: this.data.main.partialRequestsEnabled,
removeUnmonitoredFromRequestsEnabled:
this.data.main.removeUnmonitoredFromRequestsEnabled,
removeUnmonitoredEnabled: this.data.main.removeUnmonitoredEnabled,
cacheImages: this.data.main.cacheImages,
vapidPublic: this.vapidPublic,
enablePushRegistration: this.data.notifications.agents.webpush.enabled,
Expand Down
27 changes: 15 additions & 12 deletions src/components/Settings/SettingsMain/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ const messages = defineMessages('components.Settings.SettingsMain', {
validationApplicationUrl: 'You must provide a valid URL',
validationApplicationUrlTrailingSlash: 'URL must not end in a trailing slash',
partialRequestsEnabled: 'Allow Partial Series Requests',
removeUnmonitoredFromRequestsEnabled:
'Remove Request for Movies/Seasons that have been un-monitored since',
removeUnmonitoredEnabled: 'Remove Unmonitored Media',
removeUnmonitoredExplanation:
'Remove Movies/Seasons from Jellyseerr that are not available and have been un-monitored since',
locale: 'Display Language',
proxyEnabled: 'HTTP(S) Proxy',
proxyHostname: 'Proxy Hostname',
Expand Down Expand Up @@ -154,8 +155,7 @@ const SettingsMain = () => {
region: data?.region,
originalLanguage: data?.originalLanguage,
partialRequestsEnabled: data?.partialRequestsEnabled,
removeUnmonitoredFromRequestsEnabled:
data?.removeUnmonitoredFromRequestsEnabled,
removeUnmonitoredEnabled: data?.removeUnmonitoredEnabled,
trustProxy: data?.trustProxy,
cacheImages: data?.cacheImages,
proxyEnabled: data?.proxy?.enabled,
Expand Down Expand Up @@ -185,8 +185,7 @@ const SettingsMain = () => {
region: values.region,
originalLanguage: values.originalLanguage,
partialRequestsEnabled: values.partialRequestsEnabled,
removeUnmonitoredFromRequestsEnabled:
values.removeUnmonitoredFromRequestsEnabled,
removeUnmonitoredEnabled: values.removeUnmonitoredEnabled,
trustProxy: values.trustProxy,
cacheImages: values.cacheImages,
proxy: {
Expand Down Expand Up @@ -480,24 +479,28 @@ const SettingsMain = () => {
</div>
<div className="form-row">
<label
htmlFor="removeUnmonitoredFromRequestsEnabled"
htmlFor="removeUnmonitoredEnabled"
className="checkbox-label"
>
<span className="mr-2">
{intl.formatMessage(messages.removeUnmonitoredEnabled)}
</span>
<SettingsBadge badgeType="experimental" />
<span className="label-tip">
{intl.formatMessage(
messages.removeUnmonitoredFromRequestsEnabled
messages.removeUnmonitoredExplanation
)}
</span>
</label>
<div className="form-input-area">
<Field
type="checkbox"
id="removeUnmonitoredFromRequestsEnabled"
name="removeUnmonitoredFromRequestsEnabled"
id="removeUnmonitoredEnabled"
name="removeUnmonitoredEnabled"
onChange={() => {
setFieldValue(
'removeUnmonitoredFromRequestsEnabled',
!values.removeUnmonitoredFromRequestsEnabled
'removeUnmonitoredEnabled',
!values.removeUnmonitoredEnabled
);
}}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/context/SettingsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const defaultSettings = {
originalLanguage: '',
mediaServerType: MediaServerType.NOT_CONFIGURED,
partialRequestsEnabled: true,
removeUnmonitoredFromRequestsEnabled: false,
removeUnmonitoredEnabled: false,
cacheImages: false,
vapidPublic: '',
enablePushRegistration: false,
Expand Down
1 change: 0 additions & 1 deletion src/i18n/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,6 @@
"components.Settings.SettingsMain.originallanguage": "Discover Language",
"components.Settings.SettingsMain.originallanguageTip": "Filter content by original language",
"components.Settings.SettingsMain.partialRequestsEnabled": "Allow Partial Series Requests",
"components.Settings.SettingsMain.removeUnmonitoredFromRequestsEnabled": "Remove Request for Movies/Seasons that have been un-monitored since",
"components.Settings.SettingsMain.region": "Discover Region",
"components.Settings.SettingsMain.regionTip": "Filter content by regional availability",
"components.Settings.SettingsMain.toastApiKeyFailure": "Something went wrong while generating a new API key.",
Expand Down
1 change: 0 additions & 1 deletion src/i18n/locale/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,6 @@
"components.Settings.SettingsMain.trustProxy": "Activer la prise en charge proxy",
"components.Settings.SettingsMain.trustProxyTip": "Permettre Jellyseerr à enregistrer correctement les adresses IP des clients derrière un proxy",
"components.Settings.SettingsMain.partialRequestsEnabled": "Permettre les demandes partielles des séries",
"components.Settings.SettingsMain.removeUnmonitoredFromRequestsEnabled": "Supprimer les requests de Films/Séries qui ne sont plus suivis",
"components.Selector.nooptions": "Aucun résultat.",
"components.Layout.Sidebar.browsetv": "Séries",
"components.Selector.showmore": "En voir plus",
Expand Down
2 changes: 1 addition & 1 deletion src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ CoreApp.getInitialProps = async (initialProps) => {
originalLanguage: '',
mediaServerType: MediaServerType.NOT_CONFIGURED,
partialRequestsEnabled: true,
removeUnmonitoredFromRequestsEnabled: false,
removeUnmonitoredEnabled: false,
cacheImages: false,
vapidPublic: '',
enablePushRegistration: false,
Expand Down

0 comments on commit 7e9d84d

Please sign in to comment.