From 45de71539065342ca0fa5c74346cccd63992017c Mon Sep 17 00:00:00 2001 From: ajnart Date: Tue, 21 Jun 2022 19:16:29 +0200 Subject: [PATCH 1/5] :bug: Fix itteration on the different types of services --- src/components/AppShelf/AddAppShelfItem.tsx | 116 ++++++++++---------- src/pages/api/modules/downloads.ts | 44 ++++---- 2 files changed, 80 insertions(+), 80 deletions(-) diff --git a/src/components/AppShelf/AddAppShelfItem.tsx b/src/components/AppShelf/AddAppShelfItem.tsx index c4db0df50..382bd6cf4 100644 --- a/src/components/AppShelf/AddAppShelfItem.tsx +++ b/src/components/AppShelf/AddAppShelfItem.tsx @@ -298,64 +298,64 @@ export function AddAppShelfItemForm(props: { setOpened: (b: boolean) => void } & )} {form.values.type === 'qBittorrent' && ( - <> - { - form.setFieldValue('username', event.currentTarget.value); - }} - error={form.errors.username && 'Invalid username'} - /> - { - form.setFieldValue('password', event.currentTarget.value); - }} - error={form.errors.password && 'Invalid password'} - /> - - )} - {form.values.type === 'Deluge' && ( - <> - { - form.setFieldValue('password', event.currentTarget.value); - }} - error={form.errors.password && 'Invalid password'} - /> - - )} - {form.values.type === 'Transmission' && ( - <> - { - form.setFieldValue('username', event.currentTarget.value); - }} - error={form.errors.username && 'Invalid username'} - /> - { - form.setFieldValue('password', event.currentTarget.value); - }} - error={form.errors.password && 'Invalid password'} - /> - - )} + <> + { + form.setFieldValue('username', event.currentTarget.value); + }} + error={form.errors.username && 'Invalid username'} + /> + { + form.setFieldValue('password', event.currentTarget.value); + }} + error={form.errors.password && 'Invalid password'} + /> + + )} + {form.values.type === 'Deluge' && ( + <> + { + form.setFieldValue('password', event.currentTarget.value); + }} + error={form.errors.password && 'Invalid password'} + /> + + )} + {form.values.type === 'Transmission' && ( + <> + { + form.setFieldValue('username', event.currentTarget.value); + }} + error={form.errors.username && 'Invalid username'} + /> + { + form.setFieldValue('password', event.currentTarget.value); + }} + error={form.errors.password && 'Invalid password'} + /> + + )} diff --git a/src/pages/api/modules/downloads.ts b/src/pages/api/modules/downloads.ts index 87de10437..1535ae944 100644 --- a/src/pages/api/modules/downloads.ts +++ b/src/pages/api/modules/downloads.ts @@ -3,18 +3,17 @@ import { QBittorrent } from '@ctrl/qbittorrent'; import { NormalizedTorrent } from '@ctrl/shared-torrent'; import { Transmission } from '@ctrl/transmission'; import { NextApiRequest, NextApiResponse } from 'next'; +import { useConfig } from '../../../tools/state'; import { Config } from '../../../tools/types'; async function Post(req: NextApiRequest, res: NextApiResponse) { // Get the type of service from the request url - const torrents: NormalizedTorrent[] = []; - const { config }: { config: Config } = req.body; - const qBittorrentServices = config.services - .filter((service) => service.type === 'qBittorrent'); - + const { config }: { config: Config } = useConfig(); + const qBittorrentServices = config.services.filter((service) => service.type === 'qBittorrent'); const delugeServices = config.services.filter((service) => service.type === 'Deluge'); - const transmissionServices = config.services - .filter((service) => service.type === 'Transmission'); + const transmissionServices = config.services.filter((service) => service.type === 'Transmission'); + + const torrents: NormalizedTorrent[] = []; if (!qBittorrentServices && !delugeServices && !transmissionServices) { return res.status(500).json({ @@ -23,7 +22,7 @@ async function Post(req: NextApiRequest, res: NextApiResponse) { }); } if (qBittorrentServices) { - for (const service of qBittorrentServices) { + qBittorrentServices.map(async (service) => torrents.push( ...( await new QBittorrent({ @@ -32,23 +31,24 @@ async function Post(req: NextApiRequest, res: NextApiResponse) { password: service.password, }).getAllData() ).torrents - ); - } + ) + ); } if (delugeServices) { - for (const service of delugeServices) { - torrents.push( - ...( - await new Deluge({ - baseUrl: service.url, - password: 'password' in service ? service.password : '', - }).getAllData() - ).torrents - ) - } + delugeServices.map(async (service) => + torrents.push( + ...( + await new Deluge({ + baseUrl: service.url, + password: 'password' in service ? service.password : '', + }).getAllData() + ).torrents + ) + ); } if (transmissionServices) { - for (const service of transmissionServices) { + // Map transmissionServices + transmissionServices.map(async (service) => { torrents.push( ...( await new Transmission({ @@ -58,7 +58,7 @@ async function Post(req: NextApiRequest, res: NextApiResponse) { }).getAllData() ).torrents ); - } + }); } res.status(200).json(torrents); } From 7aedc4111f4a7240eadab07a3fcc684731c73aee Mon Sep 17 00:00:00 2001 From: ajnart Date: Tue, 21 Jun 2022 19:59:25 +0200 Subject: [PATCH 2/5] :ambulance: Hotfix how the result from the services are awaited --- src/pages/api/modules/downloads.ts | 75 ++++++++++++++---------------- 1 file changed, 34 insertions(+), 41 deletions(-) diff --git a/src/pages/api/modules/downloads.ts b/src/pages/api/modules/downloads.ts index 1535ae944..ccb483254 100644 --- a/src/pages/api/modules/downloads.ts +++ b/src/pages/api/modules/downloads.ts @@ -3,12 +3,11 @@ import { QBittorrent } from '@ctrl/qbittorrent'; import { NormalizedTorrent } from '@ctrl/shared-torrent'; import { Transmission } from '@ctrl/transmission'; import { NextApiRequest, NextApiResponse } from 'next'; -import { useConfig } from '../../../tools/state'; import { Config } from '../../../tools/types'; async function Post(req: NextApiRequest, res: NextApiResponse) { // Get the type of service from the request url - const { config }: { config: Config } = useConfig(); + const { config }: { config: Config } = req.body; const qBittorrentServices = config.services.filter((service) => service.type === 'qBittorrent'); const delugeServices = config.services.filter((service) => service.type === 'Deluge'); const transmissionServices = config.services.filter((service) => service.type === 'Transmission'); @@ -21,45 +20,39 @@ async function Post(req: NextApiRequest, res: NextApiResponse) { message: 'Missing services', }); } - if (qBittorrentServices) { - qBittorrentServices.map(async (service) => - torrents.push( - ...( - await new QBittorrent({ - baseUrl: service.url, - username: service.username, - password: service.password, - }).getAllData() - ).torrents - ) - ); - } - if (delugeServices) { - delugeServices.map(async (service) => - torrents.push( - ...( - await new Deluge({ - baseUrl: service.url, - password: 'password' in service ? service.password : '', - }).getAllData() - ).torrents - ) - ); - } - if (transmissionServices) { - // Map transmissionServices - transmissionServices.map(async (service) => { - torrents.push( - ...( - await new Transmission({ - baseUrl: service.url, - username: 'username' in service ? service.username : '', - password: 'password' in service ? service.password : '', - }).getAllData() - ).torrents - ); - }); - } + await Promise.all( + qBittorrentServices.map((service) => + new QBittorrent({ + baseUrl: service.url, + username: service.username, + password: service.password, + }) + .getAllData() + .then((e) => e.torrents.map((torrent) => torrents.push(torrent))) + ) + ); + await Promise.all( + delugeServices.map((service) => + new Deluge({ + baseUrl: service.url, + password: service.password, + }) + .getAllData() + .then((e) => e.torrents.map((torrent) => torrents.push(torrent))) + ) + ); + // Map transmissionServices + await Promise.all( + transmissionServices.map((service) => + new Transmission({ + baseUrl: service.url, + username: service.username, + password: service.password, + }) + .getAllData() + .then((e) => e.torrents.map((torrent) => torrents.push(torrent))) + ) + ); res.status(200).json(torrents); } From 85164d79fc54cae57731a38458d9cec81a8136af Mon Sep 17 00:00:00 2001 From: ajnart Date: Tue, 21 Jun 2022 20:35:40 +0200 Subject: [PATCH 3/5] :ambulance: Hotfix password and usernames --- src/pages/api/modules/downloads.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/api/modules/downloads.ts b/src/pages/api/modules/downloads.ts index ccb483254..0cc5236df 100644 --- a/src/pages/api/modules/downloads.ts +++ b/src/pages/api/modules/downloads.ts @@ -35,7 +35,7 @@ async function Post(req: NextApiRequest, res: NextApiResponse) { delugeServices.map((service) => new Deluge({ baseUrl: service.url, - password: service.password, + password: 'password' in service ? service.password : '', }) .getAllData() .then((e) => e.torrents.map((torrent) => torrents.push(torrent))) @@ -46,8 +46,8 @@ async function Post(req: NextApiRequest, res: NextApiResponse) { transmissionServices.map((service) => new Transmission({ baseUrl: service.url, - username: service.username, - password: service.password, + username: 'username' in service ? service.username : '', + password: 'password' in service ? service.password : '', }) .getAllData() .then((e) => e.torrents.map((torrent) => torrents.push(torrent))) From a5f477c19bf1c54e31a5e1bd43dc553a849852a3 Mon Sep 17 00:00:00 2001 From: ajnart Date: Tue, 21 Jun 2022 21:04:21 +0200 Subject: [PATCH 4/5] :ambulance: Hotfix to spread torrent pushing --- src/pages/api/modules/downloads.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/api/modules/downloads.ts b/src/pages/api/modules/downloads.ts index 0cc5236df..a38dd55f8 100644 --- a/src/pages/api/modules/downloads.ts +++ b/src/pages/api/modules/downloads.ts @@ -28,7 +28,7 @@ async function Post(req: NextApiRequest, res: NextApiResponse) { password: service.password, }) .getAllData() - .then((e) => e.torrents.map((torrent) => torrents.push(torrent))) + .then((e) => torrents.push(...e.torrents)) ) ); await Promise.all( @@ -38,7 +38,7 @@ async function Post(req: NextApiRequest, res: NextApiResponse) { password: 'password' in service ? service.password : '', }) .getAllData() - .then((e) => e.torrents.map((torrent) => torrents.push(torrent))) + .then((e) => torrents.push(...e.torrents)) ) ); // Map transmissionServices @@ -50,7 +50,7 @@ async function Post(req: NextApiRequest, res: NextApiResponse) { password: 'password' in service ? service.password : '', }) .getAllData() - .then((e) => e.torrents.map((torrent) => torrents.push(torrent))) + .then((e) => torrents.push(...e.torrents)) ) ); res.status(200).json(torrents); From 7f3db9add145c3a42b0c0af453b13d14788960b1 Mon Sep 17 00:00:00 2001 From: Thomas Camlong Date: Fri, 24 Jun 2022 13:44:43 +0200 Subject: [PATCH 5/5] :bug: Fix adding a service doesn't fetch --- src/components/modules/downloads/DownloadsModule.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/modules/downloads/DownloadsModule.tsx b/src/components/modules/downloads/DownloadsModule.tsx index 042ad4b74..03eefef29 100644 --- a/src/components/modules/downloads/DownloadsModule.tsx +++ b/src/components/modules/downloads/DownloadsModule.tsx @@ -59,7 +59,7 @@ export default function DownloadComponent() { setIsLoading(false); }); }, 5000); - }, [config.services]); + }, []); if (downloadServices.length === 0) { return (