mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-11 07:55:52 +01:00
@@ -25,37 +25,45 @@ export default function DownloadComponent() {
|
|||||||
const qBittorrentService = config.services
|
const qBittorrentService = config.services
|
||||||
.filter((service) => service.type === 'qBittorrent')
|
.filter((service) => service.type === 'qBittorrent')
|
||||||
.at(0);
|
.at(0);
|
||||||
|
const delugeService = config.services.filter((service) => service.type === 'Deluge').at(0);
|
||||||
const hideComplete: boolean =
|
const hideComplete: boolean =
|
||||||
(config?.modules?.[DownloadsModule.title]?.options?.hidecomplete?.value as boolean) ?? false;
|
(config?.modules?.[DownloadsModule.title]?.options?.hidecomplete?.value as boolean) ?? false;
|
||||||
|
|
||||||
const [torrents, setTorrents] = useState<NormalizedTorrent[]>([]);
|
const [delugeTorrents, setDelugeTorrents] = useState<NormalizedTorrent[]>([]);
|
||||||
|
const [qBittorrentTorrents, setqBittorrentTorrents] = useState<NormalizedTorrent[]>([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (qBittorrentService) {
|
if (qBittorrentService) {
|
||||||
axios.post('/api/modules/downloads', { ...qBittorrentService }).then((res) => {
|
|
||||||
setTorrents(res.data.torrents);
|
|
||||||
});
|
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
axios.post('/api/modules/downloads', { ...qBittorrentService }).then((res) => {
|
axios
|
||||||
setTorrents(res.data.torrents);
|
.post('/api/modules/downloads?dlclient=qbit', { ...qBittorrentService })
|
||||||
|
.then((res) => {
|
||||||
|
setqBittorrentTorrents(res.data.torrents);
|
||||||
|
});
|
||||||
|
}, 3000);
|
||||||
|
}
|
||||||
|
if (delugeService) {
|
||||||
|
setInterval(() => {
|
||||||
|
axios.post('/api/modules/downloads?dlclient=deluge', { ...delugeService }).then((res) => {
|
||||||
|
setDelugeTorrents(res.data.torrents);
|
||||||
});
|
});
|
||||||
}, 3000);
|
}, 3000);
|
||||||
}
|
}
|
||||||
}, [config.modules]);
|
}, [config.modules]);
|
||||||
|
|
||||||
if (!qBittorrentService) {
|
if (!qBittorrentService && !delugeService) {
|
||||||
return (
|
return (
|
||||||
<Group direction="column">
|
<Group direction="column">
|
||||||
<Title>Critical: No qBittorrent instance found in services.</Title>
|
<Title>Critical: No qBittorrent/Deluge instance found in services.</Title>
|
||||||
<Group>
|
<Group>
|
||||||
<Title order={3}>Add a qBittorrent service to view current downloads</Title>
|
<Title order={3}>Add a qBittorrent/Deluge service to view current downloads</Title>
|
||||||
<AddItemShelfButton />
|
<AddItemShelfButton />
|
||||||
</Group>
|
</Group>
|
||||||
</Group>
|
</Group>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (torrents.length === 0) {
|
if (qBittorrentTorrents.length === 0 && delugeTorrents.length === 0) {
|
||||||
return (
|
return (
|
||||||
<Center>
|
<Center>
|
||||||
<Loader />
|
<Loader />
|
||||||
@@ -71,6 +79,10 @@ export default function DownloadComponent() {
|
|||||||
<th>Progress</th>
|
<th>Progress</th>
|
||||||
</tr>
|
</tr>
|
||||||
);
|
);
|
||||||
|
// Loop over qBittorrent torrents merging with deluge torrents
|
||||||
|
const torrents: NormalizedTorrent[] = [];
|
||||||
|
delugeTorrents.forEach((torrent) => torrents.push(torrent));
|
||||||
|
qBittorrentTorrents.forEach((torrent) => torrents.push(torrent));
|
||||||
|
|
||||||
const rows = torrents.map((torrent) => {
|
const rows = torrents.map((torrent) => {
|
||||||
if (torrent.progress === 1 && hideComplete) {
|
if (torrent.progress === 1 && hideComplete) {
|
||||||
|
|||||||
@@ -1,16 +1,38 @@
|
|||||||
|
import { Deluge } from '@ctrl/deluge';
|
||||||
import { QBittorrent } from '@ctrl/qbittorrent';
|
import { QBittorrent } from '@ctrl/qbittorrent';
|
||||||
import { NextApiRequest, NextApiResponse } from 'next';
|
import { NextApiRequest, NextApiResponse } from 'next';
|
||||||
|
|
||||||
async function Post(req: NextApiRequest, res: NextApiResponse) {
|
async function Post(req: NextApiRequest, res: NextApiResponse) {
|
||||||
// Get the body
|
// Get the type of service from the request url
|
||||||
|
const { dlclient } = req.query;
|
||||||
const { body } = req;
|
const { body } = req;
|
||||||
// Get login, password and url from the body
|
// Get login, password and url from the body
|
||||||
const { username, password, url } = body;
|
const { username, password, url } = body;
|
||||||
const client = new QBittorrent({
|
if (!dlclient || (!username && !password) || !url) {
|
||||||
baseUrl: new URL(url).origin,
|
return res.status(400).json({
|
||||||
username,
|
error: 'Wrong request',
|
||||||
password,
|
});
|
||||||
});
|
}
|
||||||
|
let client: Deluge | QBittorrent;
|
||||||
|
switch (dlclient) {
|
||||||
|
case 'qbit':
|
||||||
|
client = new QBittorrent({
|
||||||
|
baseUrl: new URL(url).origin,
|
||||||
|
username,
|
||||||
|
password,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case 'deluge':
|
||||||
|
client = new Deluge({
|
||||||
|
baseUrl: new URL(url).origin,
|
||||||
|
password,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return res.status(400).json({
|
||||||
|
error: 'Wrong request',
|
||||||
|
});
|
||||||
|
}
|
||||||
const data = await client.getAllData();
|
const data = await client.getAllData();
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
torrents: data.torrents,
|
torrents: data.torrents,
|
||||||
|
|||||||
Reference in New Issue
Block a user