feat: web add more types (#114)

This commit is contained in:
Ludvig Lundgren 2022-02-05 15:20:54 +01:00 committed by GitHub
parent 6df77de953
commit 8c9f9495ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 191 additions and 137 deletions

View file

@ -48,7 +48,7 @@ interface AddProps {
}
export function IndexerAddForm({ isOpen, toggle }: AddProps) {
const { data } = useQuery<IndexerSchema[], Error>('indexerSchema', APIClient.indexers.getSchema,
const { data } = useQuery<IndexerDefinition[], Error>('indexerDefinition', APIClient.indexers.getSchema,
{
enabled: isOpen,
refetchOnWindowFocus: false
@ -154,7 +154,7 @@ export function IndexerAddForm({ isOpen, toggle }: AddProps) {
Networks, channels and invite commands are configured automatically.
</p>
</div>
{ind.irc.settings.map((f: IndexerSchemaSettings, idx: number) => {
{ind.irc.settings.map((f: IndexerSetting, idx: number) => {
switch (f.type) {
case "text":
return <TextFieldWide name={`irc.${f.name}`} label={f.label} required={f.required} key={idx} help={f.help} />
@ -230,7 +230,7 @@ export function IndexerAddForm({ isOpen, toggle }: AddProps) {
</div>
</div>
<div className="py-6 space-y-6 space-y-0 divide-y divide-gray-200 dark:divide-gray-700">
<div className="py-6 space-y-4 divide-y divide-gray-200 dark:divide-gray-700">
<div className="py-4 flex items-center justify-between space-y-1 px-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6 sm:py-5">
<div>
<label
@ -342,12 +342,14 @@ export function IndexerUpdateForm({ isOpen, toggle, indexer }: UpdateProps) {
deleteMutation.mutate(indexer.id)
}
const renderSettingFields = (settings: any[]) => {
if (settings !== []) {
const renderSettingFields = (settings: IndexerSetting[]) => {
if (settings === undefined) {
return null
}
return (
<div key="opt">
{settings && settings.map((f: any, idx: number) => {
{settings.map((f: IndexerSetting, idx: number) => {
switch (f.type) {
case "text":
return (
@ -363,14 +365,19 @@ export function IndexerUpdateForm({ isOpen, toggle, indexer }: UpdateProps) {
</div>
)
}
}
let initialValues = {
id: indexer.id,
name: indexer.name,
enabled: indexer.enabled,
identifier: indexer.identifier,
settings: indexer.settings.reduce((o: any, obj: any) => ({ ...o, [obj.name]: obj.value }), {}),
settings: indexer.settings?.reduce(
(o: Record<string, string>, obj: IndexerSetting) => ({
...o,
[obj.name]: obj.value
} as Record<string, string>),
{} as Record<string, string>
),
}
return (
@ -402,8 +409,7 @@ export function IndexerUpdateForm({ isOpen, toggle, indexer }: UpdateProps) {
{...field}
className="block w-full shadow-sm dark:bg-gray-800 sm:text-sm dark:text-white focus:ring-indigo-500 focus:border-indigo-500 border-gray-300 dark:border-gray-700 rounded-md"
/>
{meta.touched && meta.error &&
<span>{meta.error}</span>}
{meta.touched && meta.error && <span>{meta.error}</span>}
</div>
)}
</Field>

View file

@ -1,66 +0,0 @@
interface Action {
id: number;
name: string;
enabled: boolean;
type: ActionType;
exec_cmd: string;
exec_args: string;
watch_folder: string;
category: string;
tags: string;
label: string;
save_path: string;
paused: boolean;
ignore_rules: boolean;
limit_upload_speed: number;
limit_download_speed: number;
client_id: number;
filter_id: number;
}
interface Filter {
id: number;
name: string;
enabled: boolean;
shows: string;
min_size: string;
max_size: string;
match_sites: string[];
except_sites: string[];
delay: number;
years: string;
resolutions: string[];
sources: string[];
codecs: string[];
containers: string[];
match_release_types: string[];
quality: string[];
formats: string[];
media: string[];
match_hdr: string[];
except_hdr: string[];
log_score: number;
log: boolean;
cue: boolean;
perfect_flac: boolean;
artists: string;
albums: string;
seasons: string;
episodes: string;
match_releases: string;
except_releases: string;
match_release_groups: string;
except_release_groups: string;
match_categories: string;
except_categories: string;
tags: string;
except_tags: string;
match_uploaders: string;
except_uploaders: string;
freeleech: boolean;
freeleech_percent: string;
actions: Action[];
indexers: Indexer[];
}
type ActionType = 'TEST' | 'EXEC' | 'WATCH_FOLDER' | DownloadClientType;

View file

@ -6,15 +6,35 @@ type DownloadClientType =
'SONARR' |
'LIDARR';
interface DownloadClientRules {
enabled: boolean;
max_active_downloads: number;
ignore_slow_torrents: boolean;
download_speed_threshold: number;
}
interface DownloadClientBasicAuth {
auth: boolean;
username: string;
password: string;
}
interface DownloadClientSettings {
apikey?: string;
basic?: DownloadClientBasicAuth;
rules?: DownloadClientRules;
}
interface DownloadClient {
id?: number;
id: number;
name: string;
type: DownloadClientType;
enabled: boolean;
host: string;
port: number;
ssl: boolean;
username: string;
password: string;
type: DownloadClientType;
settings: object;
settings?: DownloadClientSettings;
}

72
web/src/types/Filter.d.ts vendored Normal file
View file

@ -0,0 +1,72 @@
interface Filter {
id: number;
name: string;
enabled: boolean;
created_at: Date;
updated_at: Date;
min_size: string;
max_size: string;
delay: number;
match_releases: string;
except_releases: string;
use_regex: boolean;
match_release_groups: string;
except_release_groups: string;
scene: boolean;
origins: string;
freeleech: boolean;
freeleech_percent: string;
shows: string;
seasons: string;
episodes: string;
resolutions: string[];
codecs: string[];
sources: string[];
containers: string[];
match_hdr: string[];
except_hdr: string[];
years: string;
artists: string;
albums: string;
match_release_types: string[];
except_release_types: string[];
formats: string[];
quality: string[];
media: string[];
perfect_flac: boolean;
cue: boolean;
log: boolean;
log_score: string;
match_categories: string;
except_categories: string;
match_uploaders: string;
except_uploaders: string;
tags: string;
except_tags: string;
tags_any: string;
except_tags_any: string;
actions: Action[];
indexers: Indexer[];
}
interface Action {
id: number;
name: string;
type: ActionType;
enabled: boolean;
exec_cmd?: string;
exec_args?: string;
watch_folder?: string;
category?: string;
tags?: string;
label?: string;
save_path?: string;
paused?: boolean;
ignore_rules?: boolean;
limit_upload_speed?: number;
limit_download_speed?: number;
filter_id?: number;
client_id?: number;
}
type ActionType = 'TEST' | 'EXEC' | 'WATCH_FOLDER' | DownloadClientType;

View file

@ -3,40 +3,62 @@ interface Indexer {
name: string;
identifier: string;
enabled: boolean;
settings: object | any;
type?: string;
settings: Array<IndexerSetting>;
}
interface IndexerSchema {
interface IndexerDefinition {
id?: number;
name: string;
identifier: string;
enabled?: boolean;
description: string;
language: string;
privacy: string;
protocol: string;
urls: string[];
settings: IndexerSchemaSettings[];
irc: IndexerSchemaIRC;
supports: string[];
settings: IndexerSetting[];
irc: IndexerIRC;
parse: IndexerParse;
}
interface IndexerSchemaSettings {
interface IndexerSetting {
name: string;
required?: boolean;
type: string;
required: boolean;
value?: string;
label: string;
help: string;
description: string;
default: string;
default?: string;
description?: string;
help?: string;
regex?: string;
}
interface IndexerSchemaIRC {
interface IndexerIRC {
network: string;
server: string;
port: number;
tls: boolean;
nickserv: boolean;
announcers: string[];
channels: string[];
invite: string[];
invite_command: string;
settings: IndexerSchemaSettings[];
announcers: string[];
settings: IndexerSetting[];
}
interface IndexerParse {
type: string;
lines: IndexerParseLines[];
match: IndexerParseMatch;
}
interface IndexerParseLines {
test: string[];
pattern: string;
vars: string[];
}
interface IndexerParseMatch {
torrentUrl: string;
encode: string[];
}