🚑 Hotfix how the result from the services are awaited

This commit is contained in:
ajnart
2022-06-21 19:59:25 +02:00
parent 45de715390
commit 7aedc4111f

View File

@@ -3,12 +3,11 @@ import { QBittorrent } from '@ctrl/qbittorrent';
import { NormalizedTorrent } from '@ctrl/shared-torrent'; import { NormalizedTorrent } from '@ctrl/shared-torrent';
import { Transmission } from '@ctrl/transmission'; import { Transmission } from '@ctrl/transmission';
import { NextApiRequest, NextApiResponse } from 'next'; import { NextApiRequest, NextApiResponse } from 'next';
import { useConfig } from '../../../tools/state';
import { Config } from '../../../tools/types'; 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 { config }: { config: Config } = useConfig(); 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 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');
@@ -21,45 +20,39 @@ async function Post(req: NextApiRequest, res: NextApiResponse) {
message: 'Missing services', message: 'Missing services',
}); });
} }
if (qBittorrentServices) { await Promise.all(
qBittorrentServices.map(async (service) => 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) => e.torrents.map((torrent) => torrents.push(torrent)))
).torrents )
) );
); await Promise.all(
} delugeServices.map((service) =>
if (delugeServices) { new Deluge({
delugeServices.map(async (service) => baseUrl: service.url,
torrents.push( password: service.password,
...( })
await new Deluge({ .getAllData()
baseUrl: service.url, .then((e) => e.torrents.map((torrent) => torrents.push(torrent)))
password: 'password' in service ? service.password : '', )
}).getAllData() );
).torrents // Map transmissionServices
) await Promise.all(
); transmissionServices.map((service) =>
} new Transmission({
if (transmissionServices) { baseUrl: service.url,
// Map transmissionServices username: service.username,
transmissionServices.map(async (service) => { password: service.password,
torrents.push( })
...( .getAllData()
await new Transmission({ .then((e) => e.torrents.map((torrent) => torrents.push(torrent)))
baseUrl: service.url, )
username: 'username' in service ? service.username : '', );
password: 'password' in service ? service.password : '',
}).getAllData()
).torrents
);
});
}
res.status(200).json(torrents); res.status(200).json(torrents);
} }