🔀 Merge pull request #257 from ajnart/fix-multiple-torrent-client

🐛 Fix itteration on the different types of services
This commit is contained in:
Thomas Camlong
2022-06-25 15:36:59 +02:00
committed by GitHub
2 changed files with 38 additions and 45 deletions

View File

@@ -59,7 +59,7 @@ export default function DownloadComponent() {
setIsLoading(false); setIsLoading(false);
}); });
}, 5000); }, 5000);
}, [config.services]); }, []);
if (downloadServices.length === 0) { if (downloadServices.length === 0) {
return ( return (

View File

@@ -7,14 +7,12 @@ 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 } = req.body; const { config }: { config: Config } = req.body;
const qBittorrentServices = config.services const qBittorrentServices = config.services.filter((service) => service.type === 'qBittorrent');
.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({
@@ -22,44 +20,39 @@ async function Post(req: NextApiRequest, res: NextApiResponse) {
message: 'Missing services', message: 'Missing services',
}); });
} }
if (qBittorrentServices) { await Promise.all(
for (const service of qBittorrentServices) { qBittorrentServices.map((service) =>
torrents.push( new QBittorrent({
...( baseUrl: service.url,
await new QBittorrent({ username: service.username,
baseUrl: service.url, password: service.password,
username: service.username, })
password: service.password, .getAllData()
}).getAllData() .then((e) => torrents.push(...e.torrents))
).torrents )
); );
} await Promise.all(
} delugeServices.map((service) =>
if (delugeServices) { new Deluge({
for (const service of delugeServices) { baseUrl: service.url,
torrents.push( password: 'password' in service ? service.password : '',
...( })
await new Deluge({ .getAllData()
baseUrl: service.url, .then((e) => torrents.push(...e.torrents))
password: 'password' in service ? service.password : '', )
}).getAllData() );
).torrents // Map transmissionServices
) await Promise.all(
} transmissionServices.map((service) =>
} new Transmission({
if (transmissionServices) { baseUrl: service.url,
for (const service of transmissionServices) { username: 'username' in service ? service.username : '',
torrents.push( password: 'password' in service ? service.password : '',
...( })
await new Transmission({ .getAllData()
baseUrl: service.url, .then((e) => torrents.push(...e.torrents))
username: 'username' in service ? service.username : '', )
password: 'password' in service ? service.password : '', );
}).getAllData()
).torrents
);
}
}
res.status(200).json(torrents); res.status(200).json(torrents);
} }