feat(filters): skip duplicates (#1711)

* feat(filters): skip duplicates

* fix: add interface instead of any

* fix(filters): tonullint

* feat(filters): skip dupes check month day

* chore: cleanup

* feat(db): set autoincrement id

* feat(filters): add repack and proper to dupe profile

* feat(filters): add default dupe profiles

* feat(duplicates): check audio and website

* feat(duplicates): update tests

* feat(duplicates): add toggles on addform

* feat(duplicates): fix sqlite upgrade path and initialize duplicate profiles

* feat(duplicates): simplify sqlite upgrade

avoiding temp table and unwieldy select.  Besides, FK constraints
are turned off anyway in #229.

* feat(duplicates): change CheckIsDuplicateRelease treatment of PROPER and REPACK

"Proper" and "Repack" are not parallel to the other conditions like "Title",
so they do not belong as dedup conditions.  "PROPER" means there was an issue in
the previous release, and so a PROPER is never a duplicate, even if it replaces
another PROPER.  Similarly, "REPACK" means there was an issue in the previous
release by that group, and so it is a duplicate only if we previously took a
release from a DIFFERENT group.

I have not removed Proper and Repack from the UI or the schema yet.

* feat(duplicates): update postgres schema to match sqlite

* feat(duplicates): fix web build errors

* feat(duplicates): fix postgres errors

* feat(filters): do leftjoin for duplicate profile

* fix(filters): partial update dupe profile

* go fmt `internal/domain/filter.go`

* feat(duplicates): restore straightforward logic for proper/repack

* feat(duplicates): remove mostly duplicate TV duplicate profiles

Having one profile seems the cleanest.  If somebody wants multiple
resolutions then they can add Resolution to the duplicate profile.
Tested this profile with both weekly episodic releases and daily
show releases.

* feat(release): add db indexes and sub_title

* feat(release): add IsDuplicate tests

* feat(release): update action handler

* feat(release): add more tests for skip duplicates

* feat(duplicates): check audio

* feat(duplicates): add more tests

* feat(duplicates): match edition cut and more

* fix(duplicates): tests

* fix(duplicates): missing imports

* fix(duplicates): tests

* feat(duplicates): handle sub_title edition and language in ui

* fix(duplicates): tests

* feat(duplicates): check name against normalized hash

* fix(duplicates): tests

* chore: update .gitignore to ignore .pnpm-store

* fix: tests

* fix(filters): tests

* fix: bad conflict merge

* fix: update release type in test

* fix: use vendored hot-toast

* fix: release_test.go

* fix: rss_test.go

* feat(duplicates): improve title hashing for unique check

* feat(duplicates): further improve title hashing for unique check with lang

* feat(duplicates): fix tests

* feat(duplicates): add macros IsDuplicate and DuplicateProfile ID and name

* feat(duplicates): add normalized hash match option

* fix: headlessui-state prop warning

* fix(duplicates): add missing year in daily ep normalize

* fix(duplicates): check rejections len

---------

Co-authored-by: ze0s <ze0s@riseup.net>
This commit is contained in:
kenstir 2024-12-25 16:33:46 -05:00 committed by GitHub
parent d153ac44b8
commit 4009554d10
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
49 changed files with 3792 additions and 743 deletions

View file

@ -498,7 +498,16 @@ export const APIClient = {
},
replayAction: (releaseId: number, actionId: number) => appClient.Post(
`api/release/${releaseId}/actions/${actionId}/retry`
)
),
profiles: {
duplicates: {
list: () => appClient.Get<ReleaseProfileDuplicate[]>(`api/release/profiles/duplicate`),
delete: (id: number) => appClient.Delete(`api/release/profiles/duplicate/${id}`),
store: (profile: ReleaseProfileDuplicate) => appClient.Post(`api/release/profiles/duplicate`, {
body: profile
}),
}
}
},
updates: {
check: () => appClient.Get("api/updates/check"),

View file

@ -12,7 +12,7 @@ import {
FilterKeys,
IndexerKeys,
IrcKeys, ListKeys, NotificationKeys, ProxyKeys,
ReleaseKeys,
ReleaseKeys, ReleaseProfileDuplicateKeys,
SettingsKeys
} from "@api/query_keys";
import { ColumnFilter } from "@tanstack/react-table";
@ -165,6 +165,14 @@ export const ReleasesIndexersQueryOptions = () =>
staleTime: Infinity
});
export const ReleaseProfileDuplicateList = () =>
queryOptions({
queryKey: ReleaseProfileDuplicateKeys.lists(),
queryFn: () => APIClient.release.profiles.duplicates.list(),
staleTime: 5000,
refetchOnWindowFocus: true,
});
export const ProxiesQueryOptions = () =>
queryOptions({
queryKey: ProxyKeys.lists(),

View file

@ -35,6 +35,13 @@ export const ReleaseKeys = {
latestActivity: () => [...ReleaseKeys.all, "latest-activity"] as const,
};
export const ReleaseProfileDuplicateKeys = {
all: ["releaseProfileDuplicate"] as const,
lists: () => [...ReleaseProfileDuplicateKeys.all, "list"] as const,
details: () => [...ReleaseProfileDuplicateKeys.all, "detail"] as const,
detail: (id: number) => [...ReleaseProfileDuplicateKeys.details(), id] as const,
};
export const ApiKeys = {
all: ["api_keys"] as const,
lists: () => [...ApiKeys.all, "list"] as const,

View file

@ -251,7 +251,7 @@ export function DownloadClientSelect({
export interface SelectFieldOption {
label: string;
value: string;
value: string | number | null;
}
export interface SelectFieldProps {
@ -293,7 +293,7 @@ export const Select = ({
onChange={(value) => setFieldValue(field.name, value)}
>
{({ open }) => (
<>
<div>
<Label className="flex text-xs font-bold text-gray-800 dark:text-gray-100 uppercase tracking-wide">
{tooltip ? (
<DocsTooltip label={label}>{tooltip}</DocsTooltip>
@ -364,7 +364,7 @@ export const Select = ({
</ListboxOptions>
</Transition>
</div>
</>
</div>
)}
</Listbox>
)}

15
web/src/forms/_shared.ts Normal file
View file

@ -0,0 +1,15 @@
/*
* Copyright (c) 2021 - 2024, Ludvig Lundgren and the autobrr contributors.
* SPDX-License-Identifier: GPL-2.0-or-later
*/
export interface AddFormProps {
isOpen: boolean;
toggle: () => void;
}
export interface UpdateFormProps<T> {
isOpen: boolean;
toggle: () => void;
data: T;
}

View file

@ -16,14 +16,9 @@ import { FilterKeys } from "@api/query_keys";
import { DEBUG } from "@components/debug";
import { toast } from "@components/hot-toast";
import Toast from "@components/notifications/Toast";
import { AddFormProps } from "@forms/_shared";
interface filterAddFormProps {
isOpen: boolean;
toggle: () => void;
}
export function FilterAddForm({ isOpen, toggle }: filterAddFormProps) {
export function FilterAddForm({ isOpen, toggle }: AddFormProps) {
const inputRef = useRef(null)
const queryClient = useQueryClient();
const navigate = useNavigate();

View file

@ -15,13 +15,9 @@ import { ApiKeys } from "@api/query_keys";
import { DEBUG } from "@components/debug";
import { toast } from "@components/hot-toast";
import Toast from "@components/notifications/Toast";
import { AddFormProps } from "@forms/_shared";
interface apiKeyAddFormProps {
isOpen: boolean;
toggle: () => void;
}
export function APIKeyAddForm({ isOpen, toggle }: apiKeyAddFormProps) {
export function APIKeyAddForm({ isOpen, toggle }: AddFormProps) {
const queryClient = useQueryClient();
const mutation = useMutation({

View file

@ -27,6 +27,7 @@ import {
} from "@components/inputs";
import { DocsLink, ExternalLink } from "@components/ExternalLink";
import { SelectFieldBasic } from "@components/inputs/select_wide";
import { AddFormProps, UpdateFormProps } from "@forms/_shared";
interface InitialValuesSettings {
basic?: {
@ -691,12 +692,7 @@ function DownloadClientFormButtons({
);
}
interface formProps {
isOpen: boolean;
toggle: () => void;
}
export function DownloadClientAddForm({ isOpen, toggle }: formProps) {
export function DownloadClientAddForm({ isOpen, toggle }: AddFormProps) {
const [isTesting, setIsTesting] = useState(false);
const [isSuccessfulTest, setIsSuccessfulTest] = useState(false);
const [isErrorTest, setIsErrorTest] = useState(false);
@ -856,13 +852,7 @@ export function DownloadClientAddForm({ isOpen, toggle }: formProps) {
);
}
interface updateFormProps {
isOpen: boolean;
toggle: () => void;
client: DownloadClient;
}
export function DownloadClientUpdateForm({ client, isOpen, toggle }: updateFormProps) {
export function DownloadClientUpdateForm({ isOpen, toggle, data: client}: UpdateFormProps<DownloadClient>) {
const [isTesting, setIsTesting] = useState(false);
const [isSuccessfulTest, setIsSuccessfulTest] = useState(false);
const [isErrorTest, setIsErrorTest] = useState(false);

View file

@ -18,13 +18,7 @@ import { componentMapType } from "./DownloadClientForms";
import { sleep } from "@utils";
import { ImplementationBadges } from "@screens/settings/Indexer";
import { FeedDownloadTypeOptions } from "@domain/constants";
interface UpdateProps {
isOpen: boolean;
toggle: () => void;
feed: Feed;
}
import { UpdateFormProps } from "@forms/_shared";
interface InitialValues {
id: number;
@ -41,7 +35,8 @@ interface InitialValues {
settings: FeedSettings;
}
export function FeedUpdateForm({ isOpen, toggle, feed }: UpdateProps) {
export function FeedUpdateForm({ isOpen, toggle, data}: UpdateFormProps<Feed>) {
const feed = data;
const [isTesting, setIsTesting] = useState(false);
const [isTestSuccessful, setIsSuccessfulTest] = useState(false);
const [isTestError, setIsErrorTest] = useState(false);

View file

@ -25,6 +25,7 @@ import { FeedDownloadTypeOptions } from "@domain/constants";
import { DocsLink } from "@components/ExternalLink";
import * as common from "@components/inputs/common";
import { SelectField } from "@forms/settings/IrcForms";
import { AddFormProps, UpdateFormProps } from "@forms/_shared";
// const isRequired = (message: string) => (value?: string | undefined) => (!!value ? undefined : message);
@ -255,12 +256,7 @@ type SelectValue = {
value: string;
};
export interface AddProps {
isOpen: boolean;
toggle: () => void;
}
export function IndexerAddForm({ isOpen, toggle }: AddProps) {
export function IndexerAddForm({ isOpen, toggle }: AddFormProps) {
const [indexer, setIndexer] = useState<IndexerDefinition>({} as IndexerDefinition);
const queryClient = useQueryClient();
@ -729,13 +725,7 @@ interface IndexerUpdateInitialValues {
}
}
interface UpdateProps {
isOpen: boolean;
toggle: () => void;
indexer: IndexerDefinition;
}
export function IndexerUpdateForm({ isOpen, toggle, indexer }: UpdateProps) {
export function IndexerUpdateForm({ isOpen, toggle, data: indexer }: UpdateFormProps<IndexerDefinition>) {
const queryClient = useQueryClient();
const proxies = useQuery(ProxiesQueryOptions());

View file

@ -22,6 +22,7 @@ import Toast from "@components/notifications/Toast";
import * as common from "@components/inputs/common";
import { classNames } from "@utils";
import { ProxiesQueryOptions } from "@api/queries";
import { AddFormProps, UpdateFormProps } from "@forms/_shared";
interface ChannelsFieldArrayProps {
channels: IrcChannel[];
@ -122,11 +123,6 @@ interface IrcNetworkAddFormValues {
channels: IrcChannel[];
}
interface AddFormProps {
isOpen: boolean;
toggle: () => void;
}
export function IrcNetworkAddForm({ isOpen, toggle }: AddFormProps) {
const queryClient = useQueryClient();
@ -275,17 +271,11 @@ interface IrcNetworkUpdateFormValues {
proxy_id: number;
}
interface IrcNetworkUpdateFormProps {
isOpen: boolean;
toggle: () => void;
network: IrcNetwork;
}
export function IrcNetworkUpdateForm({
isOpen,
toggle,
network
}: IrcNetworkUpdateFormProps) {
data: network
}: UpdateFormProps<IrcNetwork>) {
const queryClient = useQueryClient();
const proxies = useQuery(ProxiesQueryOptions());

View file

@ -23,6 +23,7 @@ import * as common from "@components/inputs/common";
import { NumberFieldWide, PasswordFieldWide, SwitchGroupWide, TextFieldWide } from "@components/inputs";
import { componentMapType } from "./DownloadClientForms";
import { AddFormProps, UpdateFormProps } from "@forms/_shared";
function FormFieldsDiscord() {
return (
@ -311,12 +312,7 @@ interface NotificationAddFormValues {
enabled: boolean;
}
interface AddProps {
isOpen: boolean;
toggle: () => void;
}
export function NotificationAddForm({ isOpen, toggle }: AddProps) {
export function NotificationAddForm({ isOpen, toggle }: AddFormProps) {
const queryClient = useQueryClient();
const createMutation = useMutation({
@ -565,12 +561,6 @@ const EventCheckBoxes = () => (
</fieldset>
);
interface UpdateProps {
isOpen: boolean;
toggle: () => void;
notification: ServiceNotification;
}
interface InitialValues {
id: number;
enabled: boolean;
@ -587,7 +577,7 @@ interface InitialValues {
username?: string
}
export function NotificationUpdateForm({ isOpen, toggle, notification }: UpdateProps) {
export function NotificationUpdateForm({ isOpen, toggle, data: notification }: UpdateFormProps<ServiceNotification>) {
const queryClient = useQueryClient();
const mutation = useMutation({

View file

@ -9,7 +9,7 @@ import { Dialog, DialogPanel, DialogTitle, Transition, TransitionChild } from "@
import { XMarkIcon } from "@heroicons/react/24/solid";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { AddProps } from "@forms/settings/IndexerForms";
import { AddFormProps } from "@forms/_shared";
import { DEBUG } from "@components/debug.tsx";
import { PasswordFieldWide, SwitchGroupWide, TextFieldWide } from "@components/inputs";
import { SelectFieldBasic } from "@components/inputs/select_wide";
@ -20,7 +20,7 @@ import { toast } from "@components/hot-toast";
import Toast from "@components/notifications/Toast";
import { SlideOver } from "@components/panels";
export function ProxyAddForm({ isOpen, toggle }: AddProps) {
export function ProxyAddForm({ isOpen, toggle }: AddFormProps) {
const queryClient = useQueryClient();
const createMutation = useMutation({

View file

@ -0,0 +1,198 @@
/*
* Copyright (c) 2021 - 2024, Ludvig Lundgren and the autobrr contributors.
* SPDX-License-Identifier: GPL-2.0-or-later
*/
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { APIClient } from "@api/APIClient.ts";
import { ReleaseProfileDuplicateKeys } from "@api/query_keys.ts";
import { toast } from "@components/hot-toast";
import Toast from "@components/notifications/Toast.tsx";
import { SwitchGroupWide, TextFieldWide } from "@components/inputs";
import { SlideOver } from "@components/panels";
import { AddFormProps, UpdateFormProps } from "@forms/_shared";
export function ReleaseProfileDuplicateAddForm({ isOpen, toggle }: AddFormProps) {
const queryClient = useQueryClient();
const addMutation = useMutation({
mutationFn: (profile: ReleaseProfileDuplicate) => APIClient.release.profiles.duplicates.store(profile),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ReleaseProfileDuplicateKeys.lists() });
toast.custom((t) => <Toast type="success" body="Profile was added" t={t} />);
toggle();
},
onError: () => {
toast.custom((t) => <Toast type="error" body="Profile could not be added" t={t} />);
}
});
const onSubmit = (data: unknown) => addMutation.mutate(data as ReleaseProfileDuplicate);
const initialValues: ReleaseProfileDuplicate = {
id: 0,
name: "",
protocol: false,
release_name: false,
hash: false,
title: false,
sub_title: false,
year: false,
month: false,
day: false,
source: false,
resolution: false,
codec: false,
container: false,
dynamic_range: false,
audio: false,
group: false,
season: false,
episode: false,
website: false,
proper: false,
repack: false,
edition: false,
language: false,
};
return (
<SlideOver
type="CREATE"
title="Duplicate Profile"
isOpen={isOpen}
toggle={toggle}
onSubmit={onSubmit}
initialValues={initialValues}
>
{() => (
<div className="py-2 space-y-6 sm:py-0 sm:space-y-0 divide-y divide-gray-200 dark:divide-gray-700">
<TextFieldWide required name="name" label="Name"/>
<SwitchGroupWide name="release_name" label="Release name" description="Full release name" />
<SwitchGroupWide name="hash" label="Hash" description="Normalized hash of the release name. Use with Releae name for exact match" />
<SwitchGroupWide name="title" label="Title" description="Parsed title" />
<SwitchGroupWide name="sub_title" label="Sub Title" description="Parsed Sub Title like Episode Name" />
<SwitchGroupWide name="year" label="Year" />
<SwitchGroupWide name="month" label="Month" description="For daily releases" />
<SwitchGroupWide name="day" label="Day" description="For daily releases" />
<SwitchGroupWide name="source" label="Source" />
<SwitchGroupWide name="resolution" label="Resolution" />
<SwitchGroupWide name="codec" label="Codec" />
<SwitchGroupWide name="container" label="Container" />
<SwitchGroupWide name="dynamic_range" label="Dynamic Range" />
<SwitchGroupWide name="audio" label="Audio" />
<SwitchGroupWide name="group" label="Group" description="Release group" />
<SwitchGroupWide name="season" label="Season" />
<SwitchGroupWide name="episode" label="Episode" />
<SwitchGroupWide name="website" label="Website/Service" description="Services such as AMZN/HULU/NF" />
<SwitchGroupWide name="proper" label="Proper" />
<SwitchGroupWide name="repack" label="Repack" />
<SwitchGroupWide name="edition" label="Edition" />
<SwitchGroupWide name="language" label="Language" />
</div>
)}
</SlideOver>
);
}
export function ReleaseProfileDuplicateUpdateForm({ isOpen, toggle, data: profile }: UpdateFormProps<ReleaseProfileDuplicate>) {
const queryClient = useQueryClient();
const storeMutation = useMutation({
mutationFn: (profile: ReleaseProfileDuplicate) => APIClient.release.profiles.duplicates.store(profile),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ReleaseProfileDuplicateKeys.lists() });
toast.custom((t) => <Toast type="success" body="Profile was added" t={t} />);
toggle();
},
onError: () => {
toast.custom((t) => <Toast type="error" body="Profile could not be added" t={t} />);
}
});
const onSubmit = (data: unknown) => storeMutation.mutate(data as ReleaseProfileDuplicate);
const deleteMutation = useMutation({
mutationFn: (profileId: number) => APIClient.release.profiles.duplicates.delete(profileId),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ReleaseProfileDuplicateKeys.lists() });
queryClient.invalidateQueries({ queryKey: ReleaseProfileDuplicateKeys.detail(profile.id) });
toast.custom((t) => <Toast type="success" body={`Profile ${profile.name} was deleted!`} t={t} />);
toggle();
},
});
const onDelete = () => deleteMutation.mutate(profile.id);
const initialValues: ReleaseProfileDuplicate = {
id: profile.id,
name: profile.name,
protocol: profile.protocol,
release_name: profile.release_name,
hash: profile.hash,
title: profile.title,
sub_title: profile.sub_title,
year: profile.year,
month: profile.month,
day: profile.day,
source: profile.source,
resolution: profile.resolution,
codec: profile.codec,
container: profile.container,
dynamic_range: profile.dynamic_range,
audio: profile.audio,
group: profile.group,
season: profile.season,
episode: profile.episode,
website: profile.website,
proper: profile.proper,
repack: profile.repack,
edition: profile.edition,
language: profile.language,
};
return (
<SlideOver
type="UPDATE"
title="Duplicate Profile"
isOpen={isOpen}
toggle={toggle}
deleteAction={onDelete}
onSubmit={onSubmit}
initialValues={initialValues}
>
{() => (
<div className="py-2 space-y-6 sm:py-0 sm:space-y-0 divide-y divide-gray-200 dark:divide-gray-700">
<TextFieldWide required name="name" label="Name"/>
<SwitchGroupWide name="release_name" label="Release name" description="Full release name" />
<SwitchGroupWide name="hash" label="Hash" description="Normalized hash of the release name. Use with Releae name for exact match" />
<SwitchGroupWide name="title" label="Title" description="Parsed title" />
<SwitchGroupWide name="sub_title" label="Sub Title" description="Parsed Sub Title like Episode Name" />
<SwitchGroupWide name="year" label="Year" />
<SwitchGroupWide name="month" label="Month" description="For daily releases" />
<SwitchGroupWide name="day" label="Day" description="For daily releases" />
<SwitchGroupWide name="source" label="Source" />
<SwitchGroupWide name="resolution" label="Resolution" />
<SwitchGroupWide name="codec" label="Codec" />
<SwitchGroupWide name="container" label="Container" />
<SwitchGroupWide name="dynamic_range" label="Dynamic Range (HDR,DV etc)" />
<SwitchGroupWide name="audio" label="Audio" />
<SwitchGroupWide name="group" label="Group" description="Release group" />
<SwitchGroupWide name="season" label="Season" />
<SwitchGroupWide name="episode" label="Episode" />
<SwitchGroupWide name="website" label="Website/Service" description="Services such as AMZN/HULU/NF" />
<SwitchGroupWide name="repack" label="Repack" />
<SwitchGroupWide name="proper" label="Proper" />
<SwitchGroupWide name="edition" label="Edition and Cut" />
<SwitchGroupWide name="language" label="Language and Region" />
</div>
)}
</SlideOver>
);
}

View file

@ -455,7 +455,8 @@ export const FilterDetails = () => {
max_leechers: filter.max_leechers,
indexers: filter.indexers || [],
actions: filter.actions || [],
external: filter.external || []
external: filter.external || [],
release_profile_duplicate_id: filter.release_profile_duplicate_id,
} as Filter}
onSubmit={handleSubmit}
enableReinitialize={true}

View file

@ -6,7 +6,7 @@
import { useSuspenseQuery } from "@tanstack/react-query";
import { downloadsPerUnitOptions } from "@domain/constants";
import { IndexersOptionsQueryOptions } from "@api/queries";
import { IndexersOptionsQueryOptions, ReleaseProfileDuplicateList } from "@api/queries";
import { DocsLink } from "@components/ExternalLink";
import { FilterLayout, FilterPage, FilterSection } from "./_components";
@ -16,20 +16,27 @@ import {
MultiSelectOption,
NumberField,
Select,
SelectFieldOption,
SwitchGroup,
TextField
} from "@components/inputs";
import * as CONSTS from "@domain/constants.ts";
const MapIndexer = (indexer: Indexer) => (
{ label: indexer.name, value: indexer.id } as MultiSelectOption
);
const MapReleaseProfile = (profile: ReleaseProfileDuplicate) => (
{ label: profile.name, value: profile.id } as SelectFieldOption
);
export const General = () => {
const indexersQuery = useSuspenseQuery(IndexersOptionsQueryOptions())
const indexerOptions = indexersQuery.data && indexersQuery.data.map(MapIndexer)
const duplicateProfilesQuery = useSuspenseQuery(ReleaseProfileDuplicateList())
const duplicateProfilesOptions = duplicateProfilesQuery.data && duplicateProfilesQuery.data.map(MapReleaseProfile)
// const indexerOptions = data?.map(MapIndexer) ?? [];
return (
@ -129,6 +136,13 @@ export const General = () => {
</div>
}
/>
<Select
name={`release_profile_duplicate_id`}
label="Skip Duplicates profile"
optionDefaultText="Select profile"
options={[{label: "Select profile", value: null}, ...duplicateProfilesOptions]}
tooltip={<div><p>Select the skip duplicate profile.</p></div>}
/>
</FilterLayout>
<FilterLayout>

View file

@ -106,9 +106,9 @@ function ListItem({ client }: DLSettingsItemProps) {
<li>
<div className="grid grid-cols-12 items-center py-2">
<DownloadClientUpdateForm
client={client}
isOpen={updateClientIsOpen}
toggle={toggleUpdateClient}
data={client}
/>
<div className="col-span-2 sm:col-span-1 pl-1 sm:pl-6 flex items-center">
<Checkbox

View file

@ -167,7 +167,7 @@ function ListItem({ feed }: ListItemProps) {
return (
<li key={feed.id}>
<FeedUpdateForm isOpen={updateFormIsOpen} toggle={toggleUpdateForm} feed={feed} />
<FeedUpdateForm isOpen={updateFormIsOpen} toggle={toggleUpdateForm} data={feed} />
<div className="grid grid-cols-12 items-center text-sm font-medium text-gray-900 dark:text-gray-500">
<div className="col-span-2 sm:col-span-1 pl-6 flex items-center">

View file

@ -136,7 +136,7 @@ const ListItem = ({ indexer }: ListItemProps) => {
<IndexerUpdateForm
isOpen={updateIsOpen}
toggle={toggleUpdate}
indexer={indexer}
data={indexer}
/>
<div className="col-span-2 sm:col-span-1 flex pl-1 sm:pl-5 items-center">
<Checkbox value={indexer.enabled ?? false} setValue={onToggleMutation} />

View file

@ -237,7 +237,7 @@ const ListItem = ({ network, expanded }: ListItemProps) => {
<IrcNetworkUpdateForm
isOpen={updateIsOpen}
toggle={toggleUpdate}
network={network}
data={network}
/>
<div className="col-span-2 md:col-span-1 flex pl-1 sm:pl-2.5 text-gray-500 dark:text-gray-400">
<Checkbox

View file

@ -105,7 +105,7 @@ function ListItem({ notification }: ListItemProps) {
return (
<li key={notification.id} className="text-gray-500 dark:text-gray-400">
<NotificationUpdateForm isOpen={updateFormIsOpen} toggle={toggleUpdateForm} notification={notification} />
<NotificationUpdateForm isOpen={updateFormIsOpen} toggle={toggleUpdateForm} data={notification} />
<div className="grid grid-cols-12 items-center py-2">
<div className="col-span-2 sm:col-span-1 pl-1 py-0.5 sm:pl-6 flex items-center">

View file

@ -4,7 +4,7 @@
*/
import { useRef, useState } from "react";
import { useMutation, useQueryClient, useQuery } from "@tanstack/react-query";
import { useMutation, useQueryClient, useQuery, useSuspenseQuery } from "@tanstack/react-query";
import { MultiSelect as RMSC } from "react-multi-select-component";
import { AgeSelect } from "@components/inputs"
@ -15,21 +15,150 @@ import Toast from "@components/notifications/Toast";
import { useToggle } from "@hooks/hooks";
import { DeleteModal } from "@components/modals";
import { Section } from "./_components";
import { ReleaseProfileDuplicateList } from "@api/queries.ts";
import { EmptySimple } from "@components/emptystates";
import { PlusIcon } from "@heroicons/react/24/solid";
import { ReleaseProfileDuplicateAddForm, ReleaseProfileDuplicateUpdateForm } from "@forms/settings/ReleaseForms.tsx";
import { classNames } from "@utils";
const ReleaseSettings = () => (
<Section
title="Releases"
description="Manage release history."
>
<div className="border border-red-500 rounded">
<div className="py-6 px-4 sm:p-6">
<DeleteReleases />
<div className="lg:col-span-9">
<ReleaseProfileDuplicates/>
<div className="py-6 px-4 sm:p-6">
<div className="border border-red-500 rounded">
<div className="py-6 px-4 sm:p-6">
<DeleteReleases/>
</div>
</div>
</div>
</Section>
</div>
);
interface ReleaseProfileProps {
profile: ReleaseProfileDuplicate;
}
function ReleaseProfileListItem({ profile }: ReleaseProfileProps) {
const [updatePanelIsOpen, toggleUpdatePanel] = useToggle(false);
return (
<li>
<div className="grid grid-cols-12 items-center py-2">
<ReleaseProfileDuplicateUpdateForm isOpen={updatePanelIsOpen} toggle={toggleUpdatePanel} data={profile}/>
<div
className="col-span-2 sm:col-span-2 lg:col-span-2 pl-4 sm:pl-4 pr-6 py-3 block flex-col text-sm font-medium text-gray-900 dark:text-white truncate"
title={profile.name}>
{profile.name}
</div>
<div className="col-span-9 sm:col-span-9 lg:col-span-9 pl-4 sm:pl-4 pr-6 py-3 flex gap-x-0.5 flex-row text-sm font-medium text-gray-900 dark:text-white truncate">
{profile.release_name && <EnabledPill value={profile.release_name} label="RLS" title="Release name" />}
{profile.hash && <EnabledPill value={profile.hash} label="Hash" title="Normalized hash of the release name. Use with Releae name for exact match" />}
{profile.title && <EnabledPill value={profile.title} label="Title" title="Parsed titel" />}
{profile.sub_title && <EnabledPill value={profile.sub_title} label="Sub Title" title="Parsed sub titel like Episode name" />}
{profile.group && <EnabledPill value={profile.group} label="Group" title="Releae group" />}
{profile.year && <EnabledPill value={profile.year} label="Year" title="Year" />}
{profile.month && <EnabledPill value={profile.month} label="Month" title="Month" />}
{profile.day && <EnabledPill value={profile.day} label="Day" title="Day" />}
{profile.source && <EnabledPill value={profile.source} label="Source" title="Source" />}
{profile.resolution && <EnabledPill value={profile.resolution} label="Resolution" title="Resolution" />}
{profile.codec && <EnabledPill value={profile.codec} label="Codec" title="Codec" />}
{profile.container && <EnabledPill value={profile.container} label="Container" title="Container" />}
{profile.dynamic_range && <EnabledPill value={profile.dynamic_range} label="Dynamic Range" title="Dynamic Range (HDR,DV)" />}
{profile.audio && <EnabledPill value={profile.audio} label="Audio" title="Audio formats" />}
{profile.season && <EnabledPill value={profile.season} label="Season" title="Season number" />}
{profile.episode && <EnabledPill value={profile.episode} label="Episode" title="Episode number" />}
{profile.website && <EnabledPill value={profile.website} label="Website" title="Website/Service" />}
{profile.proper && <EnabledPill value={profile.proper} label="Proper" title="Scene proper" />}
{profile.repack && <EnabledPill value={profile.repack} label="Repack" title="Scene repack" />}
{profile.edition && <EnabledPill value={profile.edition} label="Edition" title="Edition (eg. Collectors Edition) and Cut (eg. Directors Cut)" />}
{profile.language && <EnabledPill value={profile.language} label="Language" title="Language and Region" />}
</div>
<div className="col-span-1 pl-0.5 whitespace-nowrap text-center text-sm font-medium">
<span className="text-blue-600 dark:text-gray-300 hover:text-blue-900 cursor-pointer"
onClick={toggleUpdatePanel}
>
Edit
</span>
</div>
</div>
</li>
)
}
interface PillProps {
value: boolean;
label: string;
title: string;
}
const EnabledPill = ({ value, label, title }: PillProps) => (
<span title={title} className={classNames("inline-flex items-center rounded-md px-1.5 py-0.5 text-xs font-medium ring-1 ring-inset", value ? "bg-blue-100 dark:bg-blue-400/10 text-blue-700 dark:text-blue-400 ring-blue-700/10 dark:ring-blue-400/30" : "bg-gray-100 dark:bg-gray-400/10 text-gray-600 dark:text-gray-400 ring-gray-500/10 dark:ring-gray-400/30")}>
{label}
</span>
);
function ReleaseProfileDuplicates() {
const [addPanelIsOpen, toggleAdd] = useToggle(false);
const releaseProfileQuery = useSuspenseQuery(ReleaseProfileDuplicateList())
return (
<Section
title="Release Duplicate Profiles"
description="Manage duplicate profiles."
rightSide={
<button
type="button"
className="relative inline-flex items-center px-4 py-2 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-blue-600 dark:bg-blue-600 hover:bg-blue-700 dark:hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 dark:focus:ring-blue-500"
onClick={toggleAdd}
>
<PlusIcon className="h-5 w-5 mr-1"/>
Add new
</button>
}
>
<ReleaseProfileDuplicateAddForm isOpen={addPanelIsOpen} toggle={toggleAdd}/>
<div className="flex flex-col">
{releaseProfileQuery.data.length > 0 ? (
<ul className="min-w-full relative">
<li className="grid grid-cols-12 border-b border-gray-200 dark:border-gray-700">
<div
className="col-span-2 sm:col-span-1 pl-1 sm:pl-4 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">Name
</div>
{/*<div*/}
{/* className="col-span-6 sm:col-span-4 lg:col-span-4 pl-10 sm:pl-12 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider cursor-pointer"*/}
{/* // onClick={() => sortedClients.requestSort("name")}*/}
{/*>*/}
{/* Name*/}
{/*</div>*/}
{/*<div*/}
{/* className="hidden sm:flex col-span-4 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider cursor-pointer"*/}
{/* onClick={() => sortedClients.requestSort("host")}*/}
{/*>*/}
{/* Host <span className="sort-indicator">{sortedClients.getSortIndicator("host")}</span>*/}
{/*</div>*/}
{/*<div className="hidden sm:flex col-span-3 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider cursor-pointer"*/}
{/* onClick={() => sortedClients.requestSort("type")}*/}
{/*>*/}
{/* Type <span className="sort-indicator">{sortedClients.getSortIndicator("type")}</span>*/}
{/*</div>*/}
</li>
{releaseProfileQuery.data.map((profile) => (
<ReleaseProfileListItem key={profile.id} profile={profile}/>
))}
</ul>
) : (
<EmptySimple title="No duplicate rlease profiles" subtitle="" buttonText="Add new profile"
buttonAction={toggleAdd}/>
)}
</div>
</Section>
)
}
const getDurationLabel = (durationValue: number): string => {
const durationOptions: Record<number, string> = {
@ -87,11 +216,12 @@ function DeleteReleases() {
onSuccess: () => {
if (parsedDuration === 0) {
toast.custom((t) => (
<Toast type="success" body={"All releases based on criteria were deleted."} t={t} />
<Toast type="success" body={"All releases based on criteria were deleted."} t={t}/>
));
} else {
toast.custom((t) => (
<Toast type="success" body={`Releases older than ${getDurationLabel(parsedDuration ?? 0)} were deleted.`} t={t} />
<Toast type="success" body={`Releases older than ${getDurationLabel(parsedDuration ?? 0)} were deleted.`}
t={t}/>
));
}
@ -101,11 +231,15 @@ function DeleteReleases() {
const deleteOlderReleases = () => {
if (parsedDuration === undefined || isNaN(parsedDuration) || parsedDuration < 0) {
toast.custom((t) => <Toast type="error" body={"Please select a valid age."} t={t} />);
toast.custom((t) => <Toast type="error" body={"Please select a valid age."} t={t}/>);
return;
}
deleteOlderMutation.mutate({ olderThan: parsedDuration, indexers: indexers.map(i => i.value), releaseStatuses: releaseStatuses.map(rs => rs.value) });
deleteOlderMutation.mutate({
olderThan: parsedDuration,
indexers: indexers.map(i => i.value),
releaseStatuses: releaseStatuses.map(rs => rs.value)
});
};
return (
@ -122,19 +256,22 @@ function DeleteReleases() {
<div className="flex flex-col gap-2 w-full">
<div>
<h2 className="text-lg leading-4 font-bold text-gray-900 dark:text-white">Delete release history</h2>
<p className="text-sm mt-1 text-gray-500 dark:text-gray-400">
Select the criteria below to permanently delete release history records that are older than the chosen age and optionally match the selected indexers and release statuses:
<ul className="list-disc pl-5 mt-2">
<p className="text-sm mt-2 text-gray-500 dark:text-gray-400">
Select the criteria below to permanently delete release history records that are older than the chosen age
and optionally match the selected indexers and release statuses:
</p>
<ul className="list-disc pl-5 my-4 text-sm text-gray-500 dark:text-gray-400">
<li>
Older than (e.g., 6 months - all records older than 6 months will be deleted) - <strong className="text-gray-600 dark:text-gray-300">Required</strong>
Older than (e.g., 6 months - all records older than 6 months will be deleted) - <strong
className="text-gray-600 dark:text-gray-300">Required</strong>
</li>
<li>Indexers - Optional (if none selected, applies to all indexers)</li>
<li>Release statuses - Optional (if none selected, applies to all release statuses)</li>
</ul>
<p className="mt-2 text-red-600 dark:text-red-500">
<strong>Warning:</strong> If no indexers or release statuses are selected, all release history records older than the selected age will be permanently deleted, regardless of indexer or status.
</p>
</p>
<span className="pt-2 text-red-600 dark:text-red-500">
<strong>Warning:</strong> If no indexers or release statuses are selected, all release history records
older than the selected age will be permanently deleted, regardless of indexer or status.
</span>
</div>
<div className="flex flex-col sm:flex-row gap-2 pt-4 items-center text-sm">
@ -146,19 +283,23 @@ function DeleteReleases() {
<span className="text-red-600 dark:text-red-500"> *</span>
</>
),
content: <AgeSelect duration={duration} setDuration={setDuration} setParsedDuration={setParsedDuration} />
content: <AgeSelect duration={duration} setDuration={setDuration} setParsedDuration={setParsedDuration}/>
},
{
label: 'Indexers:',
content: <RMSC options={indexerOptions?.map(option => ({ value: option.identifier, label: option.name })) || []} value={indexers} onChange={setIndexers} labelledBy="Select indexers" />
content: <RMSC
options={indexerOptions?.map(option => ({ value: option.identifier, label: option.name })) || []}
value={indexers} onChange={setIndexers} labelledBy="Select indexers"/>
},
{
label: 'Release statuses:',
content: <RMSC options={releaseStatusOptions} value={releaseStatuses} onChange={setReleaseStatuses} labelledBy="Select release statuses" />
content: <RMSC options={releaseStatusOptions} value={releaseStatuses} onChange={setReleaseStatuses}
labelledBy="Select release statuses"/>
}
].map((item, index) => (
<div key={index} className="flex flex-col w-full">
<p className="text-xs font-bold text-gray-800 dark:text-gray-100 uppercase p-1 cursor-default">{item.label}</p>
<p
className="text-xs font-bold text-gray-800 dark:text-gray-100 uppercase p-1 cursor-default">{item.label}</p>
{item.content}
</div>
))}

View file

@ -82,6 +82,7 @@ interface Filter {
actions: Action[];
indexers: Indexer[];
external: ExternalFilter[];
release_profile_duplicate_id?: number;
}
interface Action {

View file

@ -74,4 +74,31 @@ interface DeleteParams {
olderThan?: number;
indexers?: string[];
releaseStatuses?: string[];
}
}
interface ReleaseProfileDuplicate {
id: number;
name: string;
protocol: boolean;
release_name: boolean;
hash: boolean;
title: boolean;
sub_title: boolean;
year: boolean;
month: boolean;
day: boolean;
source: boolean;
resolution: boolean;
codec: boolean;
container: boolean;
dynamic_range: boolean;
audio: boolean;
group: boolean;
season: boolean;
episode: boolean;
website: boolean;
proper: boolean;
repack: boolean;
edition: boolean;
language: boolean;
}