🐛 Fix itteration on the different types of services

This commit is contained in:
ajnart
2022-06-21 19:16:29 +02:00
parent c29d6f58dd
commit 45de715390
2 changed files with 80 additions and 80 deletions

View File

@@ -298,64 +298,64 @@ export function AddAppShelfItemForm(props: { setOpened: (b: boolean) => void } &
</> </>
)} )}
{form.values.type === 'qBittorrent' && ( {form.values.type === 'qBittorrent' && (
<> <>
<TextInput <TextInput
required required
label="Username" label="Username"
placeholder="admin" placeholder="admin"
value={form.values.username} value={form.values.username}
onChange={(event) => { onChange={(event) => {
form.setFieldValue('username', event.currentTarget.value); form.setFieldValue('username', event.currentTarget.value);
}} }}
error={form.errors.username && 'Invalid username'} error={form.errors.username && 'Invalid username'}
/> />
<TextInput <TextInput
required required
label="Password" label="Password"
placeholder="adminadmin" placeholder="adminadmin"
value={form.values.password} value={form.values.password}
onChange={(event) => { onChange={(event) => {
form.setFieldValue('password', event.currentTarget.value); form.setFieldValue('password', event.currentTarget.value);
}} }}
error={form.errors.password && 'Invalid password'} error={form.errors.password && 'Invalid password'}
/> />
</> </>
)} )}
{form.values.type === 'Deluge' && ( {form.values.type === 'Deluge' && (
<> <>
<TextInput <TextInput
label="Password" label="Password"
placeholder="password" placeholder="password"
value={form.values.password} value={form.values.password}
onChange={(event) => { onChange={(event) => {
form.setFieldValue('password', event.currentTarget.value); form.setFieldValue('password', event.currentTarget.value);
}} }}
error={form.errors.password && 'Invalid password'} error={form.errors.password && 'Invalid password'}
/> />
</> </>
)} )}
{form.values.type === 'Transmission' && ( {form.values.type === 'Transmission' && (
<> <>
<TextInput <TextInput
label="Username" label="Username"
placeholder="admin" placeholder="admin"
value={form.values.username} value={form.values.username}
onChange={(event) => { onChange={(event) => {
form.setFieldValue('username', event.currentTarget.value); form.setFieldValue('username', event.currentTarget.value);
}} }}
error={form.errors.username && 'Invalid username'} error={form.errors.username && 'Invalid username'}
/> />
<TextInput <TextInput
label="Password" label="Password"
placeholder="adminadmin" placeholder="adminadmin"
value={form.values.password} value={form.values.password}
onChange={(event) => { onChange={(event) => {
form.setFieldValue('password', event.currentTarget.value); form.setFieldValue('password', event.currentTarget.value);
}} }}
error={form.errors.password && 'Invalid password'} error={form.errors.password && 'Invalid password'}
/> />
</> </>
)} )}
</Group> </Group>
</ScrollArea> </ScrollArea>
</Tabs.Tab> </Tabs.Tab>

View File

@@ -3,18 +3,17 @@ import { QBittorrent } from '@ctrl/qbittorrent';
import { NormalizedTorrent } from '@ctrl/shared-torrent'; import { NormalizedTorrent } from '@ctrl/shared-torrent';
import { Transmission } from '@ctrl/transmission'; import { Transmission } from '@ctrl/transmission';
import { NextApiRequest, NextApiResponse } from 'next'; import { NextApiRequest, NextApiResponse } from 'next';
import { useConfig } from '../../../tools/state';
import { Config } from '../../../tools/types'; import { Config } from '../../../tools/types';
async function Post(req: NextApiRequest, res: NextApiResponse) { async function Post(req: NextApiRequest, res: NextApiResponse) {
// Get the type of service from the request url // Get the type of service from the request url
const torrents: NormalizedTorrent[] = []; const { config }: { config: Config } = useConfig();
const { config }: { config: Config } = req.body; const qBittorrentServices = config.services.filter((service) => service.type === 'qBittorrent');
const qBittorrentServices = config.services
.filter((service) => service.type === 'qBittorrent');
const delugeServices = config.services.filter((service) => service.type === 'Deluge'); const delugeServices = config.services.filter((service) => service.type === 'Deluge');
const transmissionServices = config.services const transmissionServices = config.services.filter((service) => service.type === 'Transmission');
.filter((service) => service.type === 'Transmission');
const torrents: NormalizedTorrent[] = [];
if (!qBittorrentServices && !delugeServices && !transmissionServices) { if (!qBittorrentServices && !delugeServices && !transmissionServices) {
return res.status(500).json({ return res.status(500).json({
@@ -23,7 +22,7 @@ async function Post(req: NextApiRequest, res: NextApiResponse) {
}); });
} }
if (qBittorrentServices) { if (qBittorrentServices) {
for (const service of qBittorrentServices) { qBittorrentServices.map(async (service) =>
torrents.push( torrents.push(
...( ...(
await new QBittorrent({ await new QBittorrent({
@@ -32,23 +31,24 @@ async function Post(req: NextApiRequest, res: NextApiResponse) {
password: service.password, password: service.password,
}).getAllData() }).getAllData()
).torrents ).torrents
); )
} );
} }
if (delugeServices) { if (delugeServices) {
for (const service of delugeServices) { delugeServices.map(async (service) =>
torrents.push( torrents.push(
...( ...(
await new Deluge({ await new Deluge({
baseUrl: service.url, baseUrl: service.url,
password: 'password' in service ? service.password : '', password: 'password' in service ? service.password : '',
}).getAllData() }).getAllData()
).torrents ).torrents
) )
} );
} }
if (transmissionServices) { if (transmissionServices) {
for (const service of transmissionServices) { // Map transmissionServices
transmissionServices.map(async (service) => {
torrents.push( torrents.push(
...( ...(
await new Transmission({ await new Transmission({
@@ -58,7 +58,7 @@ async function Post(req: NextApiRequest, res: NextApiResponse) {
}).getAllData() }).getAllData()
).torrents ).torrents
); );
} });
} }
res.status(200).json(torrents); res.status(200).json(torrents);
} }