mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-10 23:45:48 +01:00
🔀 Merge pull request #257 from ajnart/fix-multiple-torrent-client
🐛 Fix itteration on the different types of services
This commit is contained in:
@@ -59,7 +59,7 @@ export default function DownloadComponent() {
|
||||
setIsLoading(false);
|
||||
});
|
||||
}, 5000);
|
||||
}, [config.services]);
|
||||
}, []);
|
||||
|
||||
if (downloadServices.length === 0) {
|
||||
return (
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user