🔀 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);
});
}, 5000);
}, [config.services]);
}, []);
if (downloadServices.length === 0) {
return (

View File

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