🔀 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({
...(
await new QBittorrent({
baseUrl: service.url, baseUrl: service.url,
username: service.username, username: service.username,
password: service.password, password: service.password,
}).getAllData() })
).torrents .getAllData()
.then((e) => torrents.push(...e.torrents))
)
); );
} await Promise.all(
} delugeServices.map((service) =>
if (delugeServices) { new Deluge({
for (const service of delugeServices) {
torrents.push(
...(
await new Deluge({
baseUrl: service.url, baseUrl: service.url,
password: 'password' in service ? service.password : '', password: 'password' in service ? service.password : '',
}).getAllData() })
).torrents .getAllData()
.then((e) => torrents.push(...e.torrents))
) )
} );
} // Map transmissionServices
if (transmissionServices) { await Promise.all(
for (const service of transmissionServices) { transmissionServices.map((service) =>
torrents.push( new Transmission({
...(
await new Transmission({
baseUrl: service.url, baseUrl: service.url,
username: 'username' in service ? service.username : '', username: 'username' in service ? service.username : '',
password: 'password' in service ? service.password : '', password: 'password' in service ? service.password : '',
}).getAllData() })
).torrents .getAllData()
.then((e) => torrents.push(...e.torrents))
)
); );
}
}
res.status(200).json(torrents); res.status(200).json(torrents);
} }