Skip to content

Commit

Permalink
feat(requests): Request Overrides & Request Editing (#653)
Browse files Browse the repository at this point in the history
  • Loading branch information
sct authored Jan 17, 2021
1 parent d9919ab commit bdb3372
Show file tree
Hide file tree
Showing 24 changed files with 1,256 additions and 63 deletions.
100 changes: 100 additions & 0 deletions overseerr-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2507,6 +2507,26 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/MediaRequest'
put:
summary: Update a specific MediaRequest
description: Updats a specific media request and returns the request in JSON format. Requires the `MANAGE_REQUESTS` permission.

This comment has been minimized.

Copy link
@evilhyde

evilhyde Jan 18, 2021

Updates is misspelled.

tags:
- request
parameters:
- in: path
name: requestId
description: Request ID
required: true
example: 1
schema:
type: string
responses:
'200':
description: Succesfully updated request
content:
application/json:
schema:
$ref: '#/components/schemas/MediaRequest'
delete:
summary: Delete a request
description: Removes a request. If the user has the `MANAGE_REQUESTS` permission, then any request can be removed. Otherwise, only pending requests can be removed.
Expand Down Expand Up @@ -3066,6 +3086,86 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/Collection'
/service/radarr:
get:
summary: Returns non-sensitive radarr server list
description: Returns a list of radarr servers, both ID and name in JSON format
tags:
- service
responses:
'200':
description: Request successful
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/RadarrSettings'
/service/radarr/{radarrId}:
get:
summary: Returns radarr server quality profiles and root folders
description: Returns a radarr server quality profile and root folder details in JSON format
tags:
- service
parameters:
- in: path
name: radarrId
required: true
schema:
type: number
example: 0
responses:
'200':
description: Request successful
content:
application/json:
schema:
type: object
properties:
server:
$ref: '#/components/schemas/RadarrSettings'
profiles:
$ref: '#/components/schemas/ServiceProfile'
/service/sonarr:
get:
summary: Returns non-sensitive sonarr server list
description: Returns a list of sonarr servers, both ID and name in JSON format
tags:
- service
responses:
'200':
description: Request successful
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/SonarrSettings'
/service/sonarr/{sonarrId}:
get:
summary: Returns sonarr server quality profiles and root folders
description: Returns a sonarr server quality profile and root folder details in JSON format
tags:
- service
parameters:
- in: path
name: sonarrId
required: true
schema:
type: number
example: 0
responses:
'200':
description: Request successful
content:
application/json:
schema:
type: object
properties:
server:
$ref: '#/components/schemas/SonarrSettings'
profiles:
$ref: '#/components/schemas/ServiceProfile'

security:
- cookieAuth: []
Expand Down
4 changes: 2 additions & 2 deletions server/api/radarr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ interface RadarrMovie {
hasFile: boolean;
}

interface RadarrRootFolder {
export interface RadarrRootFolder {
id: number;
path: string;
freeSpace: number;
Expand All @@ -40,7 +40,7 @@ interface RadarrRootFolder {
}[];
}

interface RadarrProfile {
export interface RadarrProfile {
id: number;
name: string;
}
Expand Down
101 changes: 87 additions & 14 deletions server/entity/MediaRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export class MediaRequest {
}

if (
this.media.mediaType === MediaType.MOVIE &&
media.mediaType === MediaType.MOVIE &&
this.status === MediaRequestStatus.DECLINED
) {
if (this.is4k) {
Expand Down Expand Up @@ -284,10 +284,24 @@ export class MediaRequest {
return;
}

const radarrSettings = settings.radarr.find(
let radarrSettings = settings.radarr.find(
(radarr) => radarr.isDefault && radarr.is4k === this.is4k
);

if (
this.serverId !== null &&
this.serverId >= 0 &&
radarrSettings?.id !== this.serverId
) {
radarrSettings = settings.radarr.find(
(radarr) => radarr.id === this.serverId
);
logger.info(
`Request has an override server: ${radarrSettings?.name}`,
{ label: 'Media Request' }
);
}

if (!radarrSettings) {
logger.info(
`There is no default ${
Expand All @@ -298,6 +312,30 @@ export class MediaRequest {
return;
}

let rootFolder = radarrSettings.activeDirectory;
let qualityProfile = radarrSettings.activeProfileId;

if (
this.rootFolder &&
this.rootFolder !== '' &&
this.rootFolder !== radarrSettings.activeDirectory
) {
rootFolder = this.rootFolder;
logger.info(`Request has an override root folder: ${rootFolder}`, {
label: 'Media Request',
});
}

if (
this.profileId &&
this.profileId !== radarrSettings.activeProfileId
) {
qualityProfile = this.profileId;
logger.info(`Request has an override profile id: ${qualityProfile}`, {
label: 'Media Request',
});
}

const tmdb = new TheMovieDb();
const radarr = new RadarrAPI({
apiKey: radarrSettings.apiKey,
Expand All @@ -310,9 +348,9 @@ export class MediaRequest {
// Run this asynchronously so we don't wait for it on the UI side
radarr
.addMovie({
profileId: radarrSettings.activeProfileId,
qualityProfileId: radarrSettings.activeProfileId,
rootFolderPath: radarrSettings.activeDirectory,
profileId: qualityProfile,
qualityProfileId: qualityProfile,
rootFolderPath: rootFolder,
minimumAvailability: radarrSettings.minimumAvailability,
title: movie.title,
tmdbId: movie.id,
Expand Down Expand Up @@ -376,10 +414,24 @@ export class MediaRequest {
return;
}

const sonarrSettings = settings.sonarr.find(
let sonarrSettings = settings.sonarr.find(
(sonarr) => sonarr.isDefault && sonarr.is4k === this.is4k
);

if (
this.serverId !== null &&
this.serverId >= 0 &&
sonarrSettings?.id !== this.serverId
) {
sonarrSettings = settings.sonarr.find(
(sonarr) => sonarr.id === this.serverId
);
logger.info(
`Request has an override server: ${sonarrSettings?.name}`,
{ label: 'Media Request' }
);
}

if (!sonarrSettings) {
logger.info(
`There is no default ${
Expand Down Expand Up @@ -423,17 +475,38 @@ export class MediaRequest {
seriesType = 'anime';
}

let rootFolder =
seriesType === 'anime' && sonarrSettings.activeAnimeDirectory
? sonarrSettings.activeAnimeDirectory
: sonarrSettings.activeDirectory;
let qualityProfile =
seriesType === 'anime' && sonarrSettings.activeAnimeProfileId
? sonarrSettings.activeAnimeProfileId
: sonarrSettings.activeProfileId;

if (
this.rootFolder &&
this.rootFolder !== '' &&
this.rootFolder !== rootFolder
) {
rootFolder = this.rootFolder;
logger.info(`Request has an override root folder: ${rootFolder}`, {
label: 'Media Request',
});
}

if (this.profileId && this.profileId !== qualityProfile) {
qualityProfile = this.profileId;
logger.info(`Request has an override profile id: ${qualityProfile}`, {
label: 'Media Request',
});
}

// Run this asynchronously so we don't wait for it on the UI side
sonarr
.addSeries({
profileId:
seriesType === 'anime' && sonarrSettings.activeAnimeProfileId
? sonarrSettings.activeAnimeProfileId
: sonarrSettings.activeProfileId,
rootFolderPath:
seriesType === 'anime' && sonarrSettings.activeAnimeDirectory
? sonarrSettings.activeAnimeDirectory
: sonarrSettings.activeDirectory,
profileId: qualityProfile,
rootFolderPath: rootFolder,
title: series.name,
tvdbid: series.external_ids.tvdb_id,
seasons: this.seasons.map((season) => season.seasonNumber),
Expand Down
18 changes: 18 additions & 0 deletions server/interfaces/api/serviceInterfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { RadarrProfile, RadarrRootFolder } from '../../api/radarr';

export interface ServiceCommonServer {
id: number;
name: string;
is4k: boolean;
isDefault: boolean;
activeProfileId: number;
activeDirectory: string;
activeAnimeProfileId?: number;
activeAnimeDirectory?: string;
}

export interface ServiceCommonServerWithDetails {
server: ServiceCommonServer;
profiles: RadarrProfile[];
rootFolders: Partial<RadarrRootFolder>[];
}
1 change: 1 addition & 0 deletions server/lib/permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export enum Permission {
REQUEST_4K = 1024,
REQUEST_4K_MOVIE = 2048,
REQUEST_4K_TV = 4096,
REQUEST_ADVANCED = 8192,
}

/**
Expand Down
2 changes: 2 additions & 0 deletions server/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import mediaRoutes from './media';
import personRoutes from './person';
import collectionRoutes from './collection';
import { getAppVersion, getCommitTag } from '../utils/appVersion';
import serviceRoutes from './service';

const router = Router();

Expand Down Expand Up @@ -45,6 +46,7 @@ router.use('/tv', isAuthenticated(), tvRoutes);
router.use('/media', isAuthenticated(), mediaRoutes);
router.use('/person', isAuthenticated(), personRoutes);
router.use('/collection', isAuthenticated(), collectionRoutes);
router.use('/service', isAuthenticated(), serviceRoutes);
router.use('/auth', authRoutes);

router.get('/', (_req, res) => {
Expand Down
Loading

0 comments on commit bdb3372

Please sign in to comment.