diff --git a/server/entity/MediaRequest.ts b/server/entity/MediaRequest.ts index 61122afc..5a8d3988 100644 --- a/server/entity/MediaRequest.ts +++ b/server/entity/MediaRequest.ts @@ -764,6 +764,38 @@ export class MediaRequest { return; } + if (radarrSettings.tagRequests) { + let userTag = (await radarr.getTags()).find((v) => + v.label.startsWith(this.requestedBy.id + ' - ') + ); + if (!userTag) { + logger.info(`Requester has no active tag. Creating new`, { + label: 'Media Request', + requestId: this.id, + mediaId: this.media.id, + userId: this.requestedBy.id, + newTag: + this.requestedBy.id + ' - ' + this.requestedBy.displayName, + }); + userTag = await radarr.createTag({ + label: this.requestedBy.id + ' - ' + this.requestedBy.displayName, + }); + } + if (userTag.id) { + if (!tags?.find((v) => v === userTag?.id)) { + tags?.push(userTag.id); + } + } else { + logger.warn(`Requester has no tag and failed to add one`, { + label: 'Media Request', + requestId: this.id, + mediaId: this.media.id, + userId: this.requestedBy.id, + radarrServer: radarrSettings.hostname + ':' + radarrSettings.port, + }); + } + } + if ( media[this.is4k ? 'status4k' : 'status'] === MediaStatus.AVAILABLE ) { @@ -1022,6 +1054,38 @@ export class MediaRequest { }); } + if (sonarrSettings.tagRequests) { + let userTag = (await sonarr.getTags()).find((v) => + v.label.startsWith(this.requestedBy.id + ' - ') + ); + if (!userTag) { + logger.info(`Requester has no active tag. Creating new`, { + label: 'Media Request', + requestId: this.id, + mediaId: this.media.id, + userId: this.requestedBy.id, + newTag: + this.requestedBy.id + ' - ' + this.requestedBy.displayName, + }); + userTag = await sonarr.createTag({ + label: this.requestedBy.id + ' - ' + this.requestedBy.displayName, + }); + } + if (userTag.id) { + if (!tags?.find((v) => v === userTag?.id)) { + tags?.push(userTag.id); + } + } else { + logger.warn(`Requester has no tag and failed to add one`, { + label: 'Media Request', + requestId: this.id, + mediaId: this.media.id, + userId: this.requestedBy.id, + sonarrServer: sonarrSettings.hostname + ':' + sonarrSettings.port, + }); + } + } + const sonarrSeriesOptions: AddSeriesOptions = { profileId: qualityProfile, languageProfileId: languageProfile, diff --git a/server/lib/settings.ts b/server/lib/settings.ts index 8e66ebc5..c3981fe9 100644 --- a/server/lib/settings.ts +++ b/server/lib/settings.ts @@ -61,6 +61,7 @@ export interface DVRSettings { externalUrl?: string; syncEnabled: boolean; preventSearch: boolean; + tagRequests: boolean; } export interface RadarrSettings extends DVRSettings { diff --git a/src/components/Settings/RadarrModal/index.tsx b/src/components/Settings/RadarrModal/index.tsx index e74b0465..4ebc7a8b 100644 --- a/src/components/Settings/RadarrModal/index.tsx +++ b/src/components/Settings/RadarrModal/index.tsx @@ -57,6 +57,9 @@ const messages = defineMessages({ testFirstTags: 'Test connection to load tags', tags: 'Tags', enableSearch: 'Enable Automatic Search', + tagRequests: 'Tag Requests', + tagRequestsInfo: + "Automatically add an additional tag with the requester's user ID & display name", validationApplicationUrl: 'You must provide a valid URL', validationApplicationUrlTrailingSlash: 'URL must not end in a trailing slash', validationBaseUrlLeadingSlash: 'URL base must have a leading slash', @@ -238,6 +241,7 @@ const RadarrModal = ({ onClose, radarr, onSave }: RadarrModalProps) => { externalUrl: radarr?.externalUrl, syncEnabled: radarr?.syncEnabled ?? false, enableSearch: !radarr?.preventSearch, + tagRequests: radarr?.tagRequests ?? false, }} validationSchema={RadarrSettingsSchema} onSubmit={async (values) => { @@ -263,6 +267,7 @@ const RadarrModal = ({ onClose, radarr, onSave }: RadarrModalProps) => { externalUrl: values.externalUrl, syncEnabled: values.syncEnabled, preventSearch: !values.enableSearch, + tagRequests: values.tagRequests, }; if (!radarr) { await axios.post('/api/v1/settings/radarr', submission); @@ -713,6 +718,21 @@ const RadarrModal = ({ onClose, radarr, onSave }: RadarrModalProps) => { /> +