mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
feat(releases): support magnet links (#730)
* feat(releases): support magnet links * feat(feeds): support magnet links * feat(actions): log messages * fix: component warning * fix: check hasprefix instead of hassuffix for magnet * feat(release): resolve magnet uri from link * fix(actions): deluge use magnet uri * fix(macros): add `MagnetURI` var * fix(actions): run magnet resolving before macros * feat(feeds): set download type on creation
This commit is contained in:
parent
c6101cc765
commit
ca196f0bf1
32 changed files with 770 additions and 260 deletions
|
@ -213,10 +213,10 @@ export const SwitchGroupWide = ({
|
|||
tooltip,
|
||||
defaultValue
|
||||
}: SwitchGroupWideProps) => (
|
||||
<ul className="mt-2 px-4 divide-y divide-gray-200 dark:divide-gray-700">
|
||||
<ul className="px-4 divide-y divide-gray-200 dark:divide-gray-700">
|
||||
<Switch.Group as="li" className="py-4 flex items-center justify-between">
|
||||
<div className="flex flex-col">
|
||||
<Switch.Label as="p" className="text-sm font-medium text-gray-900 dark:text-white"
|
||||
<Switch.Label as="div" className="text-sm font-medium text-gray-900 dark:text-white"
|
||||
passive>
|
||||
<div className="flex">
|
||||
{label} {tooltip && (<CustomTooltip anchorId={name}>{tooltip}</CustomTooltip>)}
|
||||
|
|
|
@ -1,18 +1,21 @@
|
|||
import type { FieldProps } from "formik";
|
||||
import { Field } from "formik";
|
||||
import { components, ControlProps, InputProps, MenuProps, OptionProps } from "react-select";
|
||||
import Select, { components, ControlProps, InputProps, MenuProps, OptionProps } from "react-select";
|
||||
import { OptionBasicTyped } from "../../domain/constants";
|
||||
import CreatableSelect from "react-select/creatable";
|
||||
import { CustomTooltip } from "../tooltips/CustomTooltip";
|
||||
|
||||
interface SelectFieldProps<T> {
|
||||
name: string;
|
||||
label: string;
|
||||
help?: string;
|
||||
placeholder?: string;
|
||||
options: OptionBasicTyped<T>[]
|
||||
defaultValue?: OptionBasicTyped<T>;
|
||||
tooltip?: JSX.Element;
|
||||
options: OptionBasicTyped<T>[];
|
||||
}
|
||||
|
||||
export function SelectFieldCreatable<T>({ name, label, help, placeholder, options }: SelectFieldProps<T>) {
|
||||
export function SelectFieldCreatable<T>({ name, label, help, placeholder, tooltip, options }: SelectFieldProps<T>) {
|
||||
return (
|
||||
<div className="space-y-1 p-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4">
|
||||
<div>
|
||||
|
@ -20,7 +23,9 @@ export function SelectFieldCreatable<T>({ name, label, help, placeholder, option
|
|||
htmlFor={name}
|
||||
className="block text-sm font-medium text-gray-900 dark:text-white sm:pt-2"
|
||||
>
|
||||
{label}
|
||||
<div className="flex">
|
||||
{label} {tooltip && (<CustomTooltip anchorId={name}>{tooltip}</CustomTooltip>)}
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
<div className="sm:col-span-2">
|
||||
|
@ -117,3 +122,131 @@ const Option = (props: OptionProps) => {
|
|||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export function SelectField<T>({ name, label, help, placeholder, options }: SelectFieldProps<T>) {
|
||||
return (
|
||||
<div className="space-y-1 p-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4">
|
||||
<div>
|
||||
<label
|
||||
htmlFor={name}
|
||||
className="block text-sm font-medium text-gray-900 dark:text-white sm:pt-2"
|
||||
>
|
||||
{label}
|
||||
</label>
|
||||
</div>
|
||||
<div className="sm:col-span-2">
|
||||
<Field name={name} type="select">
|
||||
{({
|
||||
field,
|
||||
form: { setFieldValue }
|
||||
}: FieldProps) => (
|
||||
<Select
|
||||
{...field}
|
||||
id={name}
|
||||
components={{
|
||||
Input,
|
||||
Control,
|
||||
Menu,
|
||||
Option
|
||||
}}
|
||||
placeholder={placeholder ?? "Choose an option"}
|
||||
styles={{
|
||||
singleValue: (base) => ({
|
||||
...base,
|
||||
color: "unset"
|
||||
})
|
||||
}}
|
||||
theme={(theme) => ({
|
||||
...theme,
|
||||
spacing: {
|
||||
...theme.spacing,
|
||||
controlHeight: 30,
|
||||
baseUnit: 2
|
||||
}
|
||||
})}
|
||||
// value={field?.value ? field.value : options.find(o => o.value == field?.value)}
|
||||
value={field?.value ? { value: field.value, label: field.value } : field.value}
|
||||
onChange={(option) => {
|
||||
if (option === null) {
|
||||
setFieldValue(field.name, "");
|
||||
return;
|
||||
} else {
|
||||
setFieldValue(field.name, option.value ?? "");
|
||||
}
|
||||
}}
|
||||
options={[...[...options, { value: field.value, label: field.value }].reduce((map, obj) => map.set(obj.value, obj), new Map()).values()]}
|
||||
/>
|
||||
)}
|
||||
</Field>
|
||||
{help && (
|
||||
<p className="mt-2 text-sm text-gray-500" id={`${name}-description`}>{help}</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function SelectFieldBasic<T>({ name, label, help, placeholder, tooltip, defaultValue, options }: SelectFieldProps<T>) {
|
||||
return (
|
||||
<div className="space-y-1 p-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4">
|
||||
<div>
|
||||
<label
|
||||
htmlFor={name}
|
||||
className="block text-sm font-medium text-gray-900 dark:text-white sm:pt-2"
|
||||
>
|
||||
<div className="flex">
|
||||
{label} {tooltip && (<CustomTooltip anchorId={name}>{tooltip}</CustomTooltip>)}
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
<div className="sm:col-span-2">
|
||||
<Field name={name} type="select">
|
||||
{({
|
||||
field,
|
||||
form: { setFieldValue }
|
||||
}: FieldProps) => (
|
||||
<Select
|
||||
{...field}
|
||||
id={name}
|
||||
components={{
|
||||
Input,
|
||||
Control,
|
||||
Menu,
|
||||
Option
|
||||
}}
|
||||
placeholder={placeholder ?? "Choose an option"}
|
||||
styles={{
|
||||
singleValue: (base) => ({
|
||||
...base,
|
||||
color: "unset"
|
||||
})
|
||||
}}
|
||||
theme={(theme) => ({
|
||||
...theme,
|
||||
spacing: {
|
||||
...theme.spacing,
|
||||
controlHeight: 30,
|
||||
baseUnit: 2
|
||||
}
|
||||
})}
|
||||
defaultValue={defaultValue}
|
||||
value={field?.value && options.find(o => o.value == field?.value)}
|
||||
onChange={(option) => {
|
||||
if (option === null) {
|
||||
setFieldValue(field.name, "");
|
||||
return;
|
||||
} else {
|
||||
setFieldValue(field.name, option.value ?? "");
|
||||
}
|
||||
}}
|
||||
options={options}
|
||||
/>
|
||||
)}
|
||||
</Field>
|
||||
{help && (
|
||||
<p className="mt-2 text-sm text-gray-500" id={`${name}-description`}>{help}</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -143,7 +143,11 @@ export const releaseTypeMusic = [
|
|||
"Unknown"
|
||||
];
|
||||
|
||||
export const RELEASE_TYPE_MUSIC_OPTIONS: MultiSelectOption[] = releaseTypeMusic.map(v => ({ value: v, label: v, key: v }));
|
||||
export const RELEASE_TYPE_MUSIC_OPTIONS: MultiSelectOption[] = releaseTypeMusic.map(v => ({
|
||||
value: v,
|
||||
label: v,
|
||||
key: v
|
||||
}));
|
||||
|
||||
export const originOptions = [
|
||||
"P2P",
|
||||
|
@ -210,9 +214,9 @@ export const languageOptions = [
|
|||
export const LANGUAGE_OPTIONS = languageOptions.map(v => ({ value: v, label: v, key: v }));
|
||||
|
||||
export interface RadioFieldsetOption {
|
||||
label: string;
|
||||
description: string;
|
||||
value: ActionType;
|
||||
label: string;
|
||||
description: string;
|
||||
value: ActionType;
|
||||
}
|
||||
|
||||
export const DownloadClientTypeOptions: RadioFieldsetOption[] = [
|
||||
|
@ -330,8 +334,8 @@ export const ActionContentLayoutOptions: SelectGenericOption<ActionContentLayout
|
|||
];
|
||||
|
||||
export interface OptionBasic {
|
||||
label: string;
|
||||
value: string;
|
||||
label: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
export interface OptionBasicTyped<T> {
|
||||
|
@ -427,9 +431,9 @@ const logLevel = ["DEBUG", "INFO", "WARN", "ERROR", "TRACE"] as const;
|
|||
export const LogLevelOptions = logLevel.map(v => ({ value: v, label: v, key: v }));
|
||||
|
||||
export interface SelectOption {
|
||||
label: string;
|
||||
description: string;
|
||||
value: NotificationEvent;
|
||||
label: string;
|
||||
description: string;
|
||||
value: NotificationEvent;
|
||||
}
|
||||
|
||||
export interface SelectGenericOption<T> {
|
||||
|
@ -470,3 +474,14 @@ export const EventOptions: SelectOption[] = [
|
|||
description: "Get notified on updates"
|
||||
}
|
||||
];
|
||||
|
||||
export const FeedDownloadTypeOptions: OptionBasicTyped<FeedDownloadType>[] = [
|
||||
{
|
||||
label: "Magnet",
|
||||
value: "MAGNET"
|
||||
},
|
||||
{
|
||||
label: "Torrent",
|
||||
value: "TORRENT"
|
||||
}
|
||||
];
|
||||
|
|
|
@ -5,11 +5,13 @@ import { toast } from "react-hot-toast";
|
|||
import Toast from "../../components/notifications/Toast";
|
||||
import { SlideOver } from "../../components/panels";
|
||||
import { NumberFieldWide, PasswordFieldWide, SwitchGroupWide, TextFieldWide } from "../../components/inputs";
|
||||
import { SelectFieldBasic } from "../../components/inputs/select_wide";
|
||||
import { componentMapType } from "./DownloadClientForms";
|
||||
import { sleep } from "../../utils";
|
||||
import { useState } from "react";
|
||||
import { ImplementationBadges } from "../../screens/settings/Indexer";
|
||||
import { useFormikContext } from "formik";
|
||||
import { FeedDownloadTypeOptions } from "../../domain/constants";
|
||||
|
||||
interface UpdateProps {
|
||||
isOpen: boolean;
|
||||
|
@ -29,6 +31,7 @@ interface InitialValues {
|
|||
interval: number;
|
||||
timeout: number;
|
||||
max_age: number;
|
||||
settings: FeedSettings;
|
||||
}
|
||||
|
||||
export function FeedUpdateForm({ isOpen, toggle, feed }: UpdateProps) {
|
||||
|
@ -110,7 +113,8 @@ export function FeedUpdateForm({ isOpen, toggle, feed }: UpdateProps) {
|
|||
cookie: feed.cookie || "",
|
||||
interval: feed.interval,
|
||||
timeout: feed.timeout,
|
||||
max_age: feed.max_age
|
||||
max_age: feed.max_age,
|
||||
settings: feed.settings
|
||||
};
|
||||
|
||||
return (
|
||||
|
@ -186,6 +190,8 @@ function FormFieldsTorznab() {
|
|||
help="Torznab url"
|
||||
/>
|
||||
|
||||
<SelectFieldBasic name="settings.download_type" label="Download type" options={FeedDownloadTypeOptions} />
|
||||
|
||||
<PasswordFieldWide name="api_key" label="API key" />
|
||||
|
||||
{interval < 15 && <WarningLabel />}
|
||||
|
@ -210,6 +216,8 @@ function FormFieldsRSS() {
|
|||
help="RSS url"
|
||||
/>
|
||||
|
||||
<SelectFieldBasic name="settings.download_type" label="Download type" options={FeedDownloadTypeOptions} />
|
||||
|
||||
{interval < 15 && <WarningLabel />}
|
||||
<NumberFieldWide name="interval" label="Refresh interval" help="Minutes. Recommended 15-30. Too low and risk ban."/>
|
||||
<NumberFieldWide name="timeout" label="Refresh timeout" help="Seconds to wait before cancelling refresh."/>
|
||||
|
|
|
@ -15,9 +15,10 @@ import { APIClient } from "../../api/APIClient";
|
|||
import { PasswordFieldWide, SwitchGroupWide, TextFieldWide } from "../../components/inputs";
|
||||
import { SlideOver } from "../../components/panels";
|
||||
import Toast from "../../components/notifications/Toast";
|
||||
import { SelectFieldCreatable } from "../../components/inputs/select_wide";
|
||||
import { SelectFieldBasic, SelectFieldCreatable } from "../../components/inputs/select_wide";
|
||||
|
||||
import { CustomTooltip } from "../../components/tooltips/CustomTooltip";
|
||||
import { FeedDownloadTypeOptions } from "../../domain/constants";
|
||||
|
||||
const Input = (props: InputProps) => (
|
||||
<components.Input
|
||||
|
@ -123,6 +124,14 @@ const FeedSettingFields = (ind: IndexerDefinition, indexer: string) => {
|
|||
}
|
||||
return null;
|
||||
})}
|
||||
|
||||
<SelectFieldBasic
|
||||
name="feed.settings.download_type"
|
||||
label="Download type"
|
||||
options={FeedDownloadTypeOptions}
|
||||
tooltip={<span>Some feeds needs to force set as Magnet.</span>}
|
||||
help="Set to Torrent or Magnet depending on indexer."
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</Fragment>
|
||||
|
@ -154,6 +163,14 @@ const RSSFeedSettingFields = (ind: IndexerDefinition, indexer: string) => {
|
|||
}
|
||||
return null;
|
||||
})}
|
||||
|
||||
<SelectFieldBasic
|
||||
name="feed.settings.download_type"
|
||||
label="Download type"
|
||||
options={FeedDownloadTypeOptions}
|
||||
tooltip={<span>Some feeds needs to force set as Magnet.</span>}
|
||||
help="Set to Torrent or Magnet depending on indexer."
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</Fragment>
|
||||
|
@ -243,7 +260,8 @@ export function IndexerAddForm({ isOpen, toggle }: AddProps) {
|
|||
api_key: formData.feed.api_key,
|
||||
interval: 30,
|
||||
timeout: 60,
|
||||
indexer_id: 0
|
||||
indexer_id: 0,
|
||||
settings: formData.feed.settings
|
||||
};
|
||||
|
||||
mutation.mutate(formData as Indexer, {
|
||||
|
@ -264,7 +282,8 @@ export function IndexerAddForm({ isOpen, toggle }: AddProps) {
|
|||
url: formData.feed.url,
|
||||
interval: 30,
|
||||
timeout: 60,
|
||||
indexer_id: 0
|
||||
indexer_id: 0,
|
||||
settings: formData.feed.settings
|
||||
};
|
||||
|
||||
mutation.mutate(formData as Indexer, {
|
||||
|
|
9
web/src/types/Feed.d.ts
vendored
9
web/src/types/Feed.d.ts
vendored
|
@ -12,10 +12,18 @@ interface Feed {
|
|||
cookie: string;
|
||||
last_run: string;
|
||||
last_run_data: string;
|
||||
settings: FeedSettings;
|
||||
created_at: Date;
|
||||
updated_at: Date;
|
||||
}
|
||||
|
||||
interface FeedSettings {
|
||||
download_type: FeedDownloadType;
|
||||
// download_type: string;
|
||||
}
|
||||
|
||||
type FeedDownloadType = "MAGNET" | "TORRENT";
|
||||
|
||||
type FeedType = "TORZNAB" | "RSS";
|
||||
|
||||
interface FeedCreate {
|
||||
|
@ -27,4 +35,5 @@ interface FeedCreate {
|
|||
timeout: number;
|
||||
api_key?: string;
|
||||
indexer_id: number;
|
||||
settings: FeedSettings;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue