feat(blacklist): Automatically add media with blacklisted tags to the blacklist (#1306)
* feat(blacklist): add blacktag settings to main settings page * feat(blacklist): create blacktag logic and infrastructure * feat(blacklist): add scheduling for blacktags job * feat(blacklist): create blacktag ui badge for blacklist * docs(blacklist): document blacktags in using-jellyseerr * fix(blacklist): batch blacklist and media db removes to avoid expression tree too large error * feat(blacklist): allow easy import and export of blacktag configuration * fix(settings): don't copy the API key every time you press enter on the main settings * fix(blacklist): move filter inline with page title to match all the other pages * feat(blacklist): allow filtering between manually blacklisted and automatically blacklisted entries * docs(blacklist): reword blacktag documentation a little * refactor(blacklist): remove blacktag settings from public settings interfaces There's no reason for it to be there * refactor(blacklist): remove unused variable from processResults in blacktagsProcessor * refactor(blacklist): change all instances of blacktag to blacklistedTag and update doc to match * docs(blacklist): update general documentation for blacklisted tag settings * fix(blacklist): update setting use of "blacklisted tag" to match between modals * perf(blacklist): remove media type constraint from existing blacklist entry query Doesn't make sense to keep it because tmdbid has a unique constraint on it * fix(blacklist): remove whitespace line causing prettier to fail in CI * refactor(blacklist): swap out some != and == for !s and _s * fix(blacklist): merge back CopyButton changes, disable button when there's nothing to copy * refactor(blacklist): use axios instead of fetch for blacklisted tag queries * style(blacklist): use templated axios types and remove redundant try-catches
This commit is contained in:
@@ -1,40 +1,54 @@
|
||||
import defineMessages from '@app/utils/defineMessages';
|
||||
import Tooltip from '@app/components/Common/Tooltip';
|
||||
import { ClipboardDocumentIcon } from '@heroicons/react/24/solid';
|
||||
import { useEffect } from 'react';
|
||||
import { useIntl } from 'react-intl';
|
||||
import React, { useEffect } from 'react';
|
||||
import type { Config } from 'react-popper-tooltip';
|
||||
import { useToasts } from 'react-toast-notifications';
|
||||
import useClipboard from 'react-use-clipboard';
|
||||
|
||||
const messages = defineMessages('components.Settings', {
|
||||
copied: 'Copied API key to clipboard.',
|
||||
});
|
||||
type CopyButtonProps = {
|
||||
textToCopy: string;
|
||||
disabled?: boolean;
|
||||
toastMessage?: string;
|
||||
|
||||
const CopyButton = ({ textToCopy }: { textToCopy: string }) => {
|
||||
const intl = useIntl();
|
||||
tooltipContent?: React.ReactNode;
|
||||
tooltipConfig?: Partial<Config>;
|
||||
};
|
||||
|
||||
const CopyButton = ({
|
||||
textToCopy,
|
||||
disabled,
|
||||
toastMessage,
|
||||
tooltipContent,
|
||||
tooltipConfig,
|
||||
}: CopyButtonProps) => {
|
||||
const [isCopied, setCopied] = useClipboard(textToCopy, {
|
||||
successDuration: 1000,
|
||||
});
|
||||
const { addToast } = useToasts();
|
||||
|
||||
useEffect(() => {
|
||||
if (isCopied) {
|
||||
addToast(intl.formatMessage(messages.copied), {
|
||||
if (isCopied && toastMessage) {
|
||||
addToast(toastMessage, {
|
||||
appearance: 'info',
|
||||
autoDismiss: true,
|
||||
});
|
||||
}
|
||||
}, [isCopied, addToast, intl]);
|
||||
}, [isCopied, addToast, toastMessage]);
|
||||
|
||||
return (
|
||||
<button
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
setCopied();
|
||||
}}
|
||||
className="input-action"
|
||||
>
|
||||
<ClipboardDocumentIcon />
|
||||
</button>
|
||||
<Tooltip content={tooltipContent} tooltipConfig={tooltipConfig}>
|
||||
<button
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
setCopied();
|
||||
}}
|
||||
className="input-action"
|
||||
type="button"
|
||||
disabled={disabled}
|
||||
>
|
||||
<ClipboardDocumentIcon />
|
||||
</button>
|
||||
</Tooltip>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -68,11 +68,14 @@ const messages: { [messageName: string]: MessageDescriptor } = defineMessages(
|
||||
'download-sync': 'Download Sync',
|
||||
'download-sync-reset': 'Download Sync Reset',
|
||||
'image-cache-cleanup': 'Image Cache Cleanup',
|
||||
'process-blacklisted-tags': 'Process Blacklisted Tags',
|
||||
editJobSchedule: 'Modify Job',
|
||||
jobScheduleEditSaved: 'Job edited successfully!',
|
||||
jobScheduleEditFailed: 'Something went wrong while saving the job.',
|
||||
editJobScheduleCurrent: 'Current Frequency',
|
||||
editJobSchedulePrompt: 'New Frequency',
|
||||
editJobScheduleSelectorDays:
|
||||
'Every {jobScheduleDays, plural, one {day} other {{jobScheduleDays} days}}',
|
||||
editJobScheduleSelectorHours:
|
||||
'Every {jobScheduleHours, plural, one {hour} other {{jobScheduleHours} hours}}',
|
||||
editJobScheduleSelectorMinutes:
|
||||
@@ -92,7 +95,7 @@ interface Job {
|
||||
id: JobId;
|
||||
name: string;
|
||||
type: 'process' | 'command';
|
||||
interval: 'seconds' | 'minutes' | 'hours' | 'fixed';
|
||||
interval: 'seconds' | 'minutes' | 'hours' | 'days' | 'fixed';
|
||||
cronSchedule: string;
|
||||
nextExecutionTime: string;
|
||||
running: boolean;
|
||||
@@ -101,13 +104,20 @@ interface Job {
|
||||
type JobModalState = {
|
||||
isOpen?: boolean;
|
||||
job?: Job;
|
||||
scheduleDays: number;
|
||||
scheduleHours: number;
|
||||
scheduleMinutes: number;
|
||||
scheduleSeconds: number;
|
||||
};
|
||||
|
||||
type JobModalAction =
|
||||
| { type: 'set'; hours?: number; minutes?: number; seconds?: number }
|
||||
| {
|
||||
type: 'set';
|
||||
days?: number;
|
||||
hours?: number;
|
||||
minutes?: number;
|
||||
seconds?: number;
|
||||
}
|
||||
| {
|
||||
type: 'close';
|
||||
}
|
||||
@@ -128,6 +138,7 @@ const jobModalReducer = (
|
||||
return {
|
||||
isOpen: true,
|
||||
job: action.job,
|
||||
scheduleDays: 1,
|
||||
scheduleHours: 1,
|
||||
scheduleMinutes: 5,
|
||||
scheduleSeconds: 30,
|
||||
@@ -136,6 +147,7 @@ const jobModalReducer = (
|
||||
case 'set':
|
||||
return {
|
||||
...state,
|
||||
scheduleDays: action.days ?? state.scheduleDays,
|
||||
scheduleHours: action.hours ?? state.scheduleHours,
|
||||
scheduleMinutes: action.minutes ?? state.scheduleMinutes,
|
||||
scheduleSeconds: action.seconds ?? state.scheduleSeconds,
|
||||
@@ -164,6 +176,7 @@ const SettingsJobs = () => {
|
||||
|
||||
const [jobModalState, dispatch] = useReducer(jobModalReducer, {
|
||||
isOpen: false,
|
||||
scheduleDays: 1,
|
||||
scheduleHours: 1,
|
||||
scheduleMinutes: 5,
|
||||
scheduleSeconds: 30,
|
||||
@@ -239,6 +252,9 @@ const SettingsJobs = () => {
|
||||
jobScheduleCron[1] = `*/${jobModalState.scheduleMinutes}`;
|
||||
} else if (jobModalState.job?.interval === 'hours') {
|
||||
jobScheduleCron[2] = `*/${jobModalState.scheduleHours}`;
|
||||
} else if (jobModalState.job?.interval === 'days') {
|
||||
jobScheduleCron[2] = '1';
|
||||
jobScheduleCron[3] = `*/${jobModalState.scheduleDays}`;
|
||||
} else {
|
||||
// jobs with interval: fixed should not be editable
|
||||
throw new Error();
|
||||
@@ -367,6 +383,29 @@ const SettingsJobs = () => {
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
) : jobModalState.job?.interval === 'days' ? (
|
||||
<select
|
||||
name="jobScheduleDays"
|
||||
className="inline"
|
||||
value={jobModalState.scheduleDays}
|
||||
onChange={(e) =>
|
||||
dispatch({
|
||||
type: 'set',
|
||||
days: Number(e.target.value),
|
||||
})
|
||||
}
|
||||
>
|
||||
{[1, 2, 3, 4, 5, 6, 7, 10, 14, 21].map((v) => (
|
||||
<option value={v} key={`jobScheduleDays-${v}`}>
|
||||
{intl.formatMessage(
|
||||
messages.editJobScheduleSelectorDays,
|
||||
{
|
||||
jobScheduleDays: v,
|
||||
}
|
||||
)}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
) : (
|
||||
<select
|
||||
name="jobScheduleHours"
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import BlacklistedTagsSelector from '@app/components/BlacklistedTagsSelector';
|
||||
import Button from '@app/components/Common/Button';
|
||||
import LoadingSpinner from '@app/components/Common/LoadingSpinner';
|
||||
import PageTitle from '@app/components/Common/PageTitle';
|
||||
@@ -29,12 +30,19 @@ const messages = defineMessages('components.Settings.SettingsMain', {
|
||||
generalsettingsDescription:
|
||||
'Configure global and default settings for Jellyseerr.',
|
||||
apikey: 'API Key',
|
||||
apikeyCopied: 'Copied API key to clipboard.',
|
||||
applicationTitle: 'Application Title',
|
||||
applicationurl: 'Application URL',
|
||||
discoverRegion: 'Discover Region',
|
||||
discoverRegionTip: 'Filter content by regional availability',
|
||||
originallanguage: 'Discover Language',
|
||||
originallanguageTip: 'Filter content by original language',
|
||||
blacklistedTags: 'Blacklist Content with Tags',
|
||||
blacklistedTagsTip:
|
||||
'Automatically add content with tags to the blacklist using the "Process Blacklisted Tags" job',
|
||||
blacklistedTagsLimit: 'Limit Content Blacklisted per Tag',
|
||||
blacklistedTagsLimitTip:
|
||||
'The "Process Blacklisted Tags" job will blacklist this many pages into each sort. Larger numbers will create a more accurate blacklist, but use more space.',
|
||||
streamingRegion: 'Streaming Region',
|
||||
streamingRegionTip: 'Show streaming sites by regional availability',
|
||||
toastApiKeySuccess: 'New API key generated successfully!',
|
||||
@@ -81,6 +89,17 @@ const SettingsMain = () => {
|
||||
intl.formatMessage(messages.validationApplicationUrlTrailingSlash),
|
||||
(value) => !value || !value.endsWith('/')
|
||||
),
|
||||
blacklistedTagsLimit: Yup.number()
|
||||
.test(
|
||||
'positive',
|
||||
'Number must be greater than 0.',
|
||||
(value) => (value ?? 0) >= 0
|
||||
)
|
||||
.test(
|
||||
'lte-250',
|
||||
'Number must be less than or equal to 250.',
|
||||
(value) => (value ?? 0) <= 250
|
||||
),
|
||||
});
|
||||
|
||||
const regenerate = async () => {
|
||||
@@ -130,6 +149,8 @@ const SettingsMain = () => {
|
||||
discoverRegion: data?.discoverRegion,
|
||||
originalLanguage: data?.originalLanguage,
|
||||
streamingRegion: data?.streamingRegion || 'US',
|
||||
blacklistedTags: data?.blacklistedTags,
|
||||
blacklistedTagsLimit: data?.blacklistedTagsLimit || 50,
|
||||
partialRequestsEnabled: data?.partialRequestsEnabled,
|
||||
enableSpecialEpisodes: data?.enableSpecialEpisodes,
|
||||
cacheImages: data?.cacheImages,
|
||||
@@ -146,6 +167,8 @@ const SettingsMain = () => {
|
||||
discoverRegion: values.discoverRegion,
|
||||
streamingRegion: values.streamingRegion,
|
||||
originalLanguage: values.originalLanguage,
|
||||
blacklistedTags: values.blacklistedTags,
|
||||
blacklistedTagsLimit: values.blacklistedTagsLimit,
|
||||
partialRequestsEnabled: values.partialRequestsEnabled,
|
||||
enableSpecialEpisodes: values.enableSpecialEpisodes,
|
||||
cacheImages: values.cacheImages,
|
||||
@@ -201,6 +224,9 @@ const SettingsMain = () => {
|
||||
/>
|
||||
<CopyButton
|
||||
textToCopy={data?.apiKey ?? ''}
|
||||
toastMessage={intl.formatMessage(
|
||||
messages.apikeyCopied
|
||||
)}
|
||||
key={data?.apiKey}
|
||||
/>
|
||||
<button
|
||||
@@ -209,6 +235,7 @@ const SettingsMain = () => {
|
||||
regenerate();
|
||||
}}
|
||||
className="input-action"
|
||||
type="button"
|
||||
>
|
||||
<ArrowPathIcon />
|
||||
</button>
|
||||
@@ -352,6 +379,49 @@ const SettingsMain = () => {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="form-row">
|
||||
<label htmlFor="blacklistedTags" className="text-label">
|
||||
<span>{intl.formatMessage(messages.blacklistedTags)}</span>
|
||||
<span className="label-tip">
|
||||
{intl.formatMessage(messages.blacklistedTagsTip)}
|
||||
</span>
|
||||
</label>
|
||||
<div className="form-input-area">
|
||||
<div className="form-input-field relative z-10">
|
||||
<BlacklistedTagsSelector
|
||||
defaultValue={values.blacklistedTags}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="form-row">
|
||||
<label htmlFor="blacklistedTagsLimit" className="text-label">
|
||||
<span className="mr-2">
|
||||
{intl.formatMessage(messages.blacklistedTagsLimit)}
|
||||
</span>
|
||||
<SettingsBadge badgeType="advanced" />
|
||||
<span className="label-tip">
|
||||
{intl.formatMessage(messages.blacklistedTagsLimitTip)}
|
||||
</span>
|
||||
</label>
|
||||
<div className="form-input-area">
|
||||
<Field
|
||||
id="blacklistedTagsLimit"
|
||||
name="blacklistedTagsLimit"
|
||||
type="text"
|
||||
inputMode="numeric"
|
||||
className="short"
|
||||
placeholder={50}
|
||||
/>
|
||||
{errors.blacklistedTagsLimit &&
|
||||
touched.blacklistedTagsLimit &&
|
||||
typeof errors.blacklistedTagsLimit === 'string' && (
|
||||
<div className="error">
|
||||
{errors.blacklistedTagsLimit}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="form-row">
|
||||
<label htmlFor="hideAvailable" className="checkbox-label">
|
||||
<span className="mr-2">
|
||||
|
||||
Reference in New Issue
Block a user