mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-11 07:55:52 +01:00
🐛 Fix itteration on the different types of services
This commit is contained in:
@@ -3,18 +3,17 @@ 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 torrents: NormalizedTorrent[] = [];
|
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
|
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({
|
||||||
@@ -23,7 +22,7 @@ async function Post(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (qBittorrentServices) {
|
if (qBittorrentServices) {
|
||||||
for (const service of qBittorrentServices) {
|
qBittorrentServices.map(async (service) =>
|
||||||
torrents.push(
|
torrents.push(
|
||||||
...(
|
...(
|
||||||
await new QBittorrent({
|
await new QBittorrent({
|
||||||
@@ -32,11 +31,11 @@ async function Post(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
password: service.password,
|
password: service.password,
|
||||||
}).getAllData()
|
}).getAllData()
|
||||||
).torrents
|
).torrents
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (delugeServices) {
|
if (delugeServices) {
|
||||||
for (const service of delugeServices) {
|
delugeServices.map(async (service) =>
|
||||||
torrents.push(
|
torrents.push(
|
||||||
...(
|
...(
|
||||||
await new Deluge({
|
await new Deluge({
|
||||||
@@ -45,10 +44,11 @@ async function Post(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
}).getAllData()
|
}).getAllData()
|
||||||
).torrents
|
).torrents
|
||||||
)
|
)
|
||||||
}
|
);
|
||||||
}
|
}
|
||||||
if (transmissionServices) {
|
if (transmissionServices) {
|
||||||
for (const service of transmissionServices) {
|
// Map transmissionServices
|
||||||
|
transmissionServices.map(async (service) => {
|
||||||
torrents.push(
|
torrents.push(
|
||||||
...(
|
...(
|
||||||
await new Transmission({
|
await new Transmission({
|
||||||
@@ -58,7 +58,7 @@ async function Post(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
}).getAllData()
|
}).getAllData()
|
||||||
).torrents
|
).torrents
|
||||||
);
|
);
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
res.status(200).json(torrents);
|
res.status(200).json(torrents);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user