FR: Transmission Integration

Fixes #147
This commit is contained in:
ajnart
2022-06-06 21:38:50 +02:00
parent 39d66faf4e
commit 80a94d3778
7 changed files with 122 additions and 104 deletions

View File

@@ -27,6 +27,7 @@
"@ctrl/deluge": "^4.0.0", "@ctrl/deluge": "^4.0.0",
"@ctrl/qbittorrent": "^4.0.0", "@ctrl/qbittorrent": "^4.0.0",
"@ctrl/shared-torrent": "^4.1.0", "@ctrl/shared-torrent": "^4.1.0",
"@ctrl/transmission": "^4.1.1",
"@dnd-kit/core": "^6.0.1", "@dnd-kit/core": "^6.0.1",
"@dnd-kit/sortable": "^7.0.0", "@dnd-kit/sortable": "^7.0.0",
"@dnd-kit/utilities": "^3.2.0", "@dnd-kit/utilities": "^3.2.0",

View File

@@ -294,20 +294,21 @@ export function AddAppShelfItemForm(props: { setOpened: (b: boolean) => void } &
/> />
</> </>
)} )}
{form.values.type === 'Deluge' && ( {form.values.type === 'Deluge' ||
<> (form.values.type === 'Transmission' && (
<TextInput <>
required <TextInput
label="Password" required
placeholder="deluge" label="Password"
value={form.values.password} placeholder="password"
onChange={(event) => { value={form.values.password}
form.setFieldValue('password', event.currentTarget.value); onChange={(event) => {
}} form.setFieldValue('password', event.currentTarget.value);
error={form.errors.password && 'Invalid password'} }}
/> error={form.errors.password && 'Invalid password'}
</> />
)} </>
))}
</Group> </Group>
<Group grow position="center" mt="xl"> <Group grow position="center" mt="xl">

View File

@@ -23,36 +23,27 @@ export const DownloadsModule: IModule = {
export default function DownloadComponent() { export default function DownloadComponent() {
const { config } = useConfig(); const { config } = useConfig();
const qBittorrentService = config.services const downloadServices =
.filter((service) => service.type === 'qBittorrent') config.services.filter(
.at(0); (service) =>
const delugeService = config.services.filter((service) => service.type === 'Deluge').at(0); service.type === 'qBittorrent' ||
service.type === 'Transmission' ||
service.type === 'Deluge'
) ?? [];
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[]>([]);
const setSafeInterval = useSetSafeInterval(); const setSafeInterval = useSetSafeInterval();
useEffect(() => { useEffect(() => {
if (qBittorrentService) { setSafeInterval(() => {
setSafeInterval(() => { // Send one request with each download service inside
axios axios.post('/api/modules/downloads', { config }).then((response) => {
.post('/api/modules/downloads?dlclient=qbit', { ...qBittorrentService }) setTorrents(response.data);
.then((res) => { });
setqBittorrentTorrents(res.data.torrents); }, 1000);
});
}, 3000);
}
if (delugeService) {
setSafeInterval(() => {
axios.post('/api/modules/downloads?dlclient=deluge', { ...delugeService }).then((res) => {
setDelugeTorrents(res.data.torrents);
});
}, 3000);
}
}, [config.modules]); }, [config.modules]);
if (!qBittorrentService && !delugeService) { if (downloadServices.length === 0) {
return ( return (
<Group direction="column"> <Group direction="column">
<Title order={3}>No supported download clients found!</Title> <Title order={3}>No supported download clients found!</Title>
@@ -64,7 +55,7 @@ export default function DownloadComponent() {
); );
} }
if (qBittorrentTorrents.length === 0 && delugeTorrents.length === 0) { if (torrents.length === 0) {
return ( return (
<> <>
<Skeleton height={40} mt={10} /> <Skeleton height={40} mt={10} />
@@ -85,11 +76,6 @@ export default function DownloadComponent() {
</tr> </tr>
); );
// Loop over qBittorrent torrents merging with deluge torrents // Loop over qBittorrent torrents merging with deluge torrents
const torrents: NormalizedTorrent[] = [];
delugeTorrents.forEach((delugeTorrent) =>
torrents.push({ ...delugeTorrent, progress: delugeTorrent.progress / 100 })
);
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) {
return []; return [];

View File

@@ -57,42 +57,28 @@ interface torrentHistory {
} }
export default function TotalDownloadsComponent() { export default function TotalDownloadsComponent() {
const setSafeInterval = useSetSafeInterval();
const { config } = useConfig(); const { config } = useConfig();
const qBittorrentService = config.services const downloadServices =
.filter((service) => service.type === 'qBittorrent') config.services.filter(
.at(0); (service) =>
const delugeService = config.services.filter((service) => service.type === 'Deluge').at(0); service.type === 'qBittorrent' ||
service.type === 'Transmission' ||
service.type === 'Deluge'
) ?? [];
const [delugeTorrents, setDelugeTorrents] = useState<NormalizedTorrent[]>([]);
const [torrentHistory, torrentHistoryHandlers] = useListState<torrentHistory>([]); const [torrentHistory, torrentHistoryHandlers] = useListState<torrentHistory>([]);
const [qBittorrentTorrents, setqBittorrentTorrents] = useState<NormalizedTorrent[]>([]); const [torrents, setTorrents] = useState<NormalizedTorrent[]>([]);
const torrents: NormalizedTorrent[] = [];
delugeTorrents.forEach((delugeTorrent) =>
torrents.push({ ...delugeTorrent, progress: delugeTorrent.progress / 100 })
);
qBittorrentTorrents.forEach((torrent) => torrents.push(torrent));
const totalDownloadSpeed = torrents.reduce((acc, torrent) => acc + torrent.downloadSpeed, 0); const totalDownloadSpeed = torrents.reduce((acc, torrent) => acc + torrent.downloadSpeed, 0);
const totalUploadSpeed = torrents.reduce((acc, torrent) => acc + torrent.uploadSpeed, 0); const totalUploadSpeed = torrents.reduce((acc, torrent) => acc + torrent.uploadSpeed, 0);
const setSafeInterval = useSetSafeInterval();
useEffect(() => { useEffect(() => {
setSafeInterval(() => { setSafeInterval(() => {
// Get the current download speed of qBittorrent. axios.post('/api/modules/downloads', { config }).then((response) => {
if (qBittorrentService) { setTorrents(response.data);
axios });
.post('/api/modules/downloads?dlclient=qbit', { ...qBittorrentService })
.then((res) => {
setqBittorrentTorrents(res.data.torrents);
});
if (delugeService) {
axios.post('/api/modules/downloads?dlclient=deluge', { ...delugeService }).then((res) => {
setDelugeTorrents(res.data.torrents);
});
}
}
}, 1000); }, 1000);
}, [config.modules]); }, []);
useEffect(() => { useEffect(() => {
torrentHistoryHandlers.append({ torrentHistoryHandlers.append({
@@ -102,7 +88,7 @@ export default function TotalDownloadsComponent() {
}); });
}, [totalDownloadSpeed, totalUploadSpeed]); }, [totalDownloadSpeed, totalUploadSpeed]);
if (!qBittorrentService && !delugeService) { if (downloadServices.length === 0) {
return ( return (
<Group direction="column"> <Group direction="column">
<Title order={4}>No supported download clients found!</Title> <Title order={4}>No supported download clients found!</Title>

View File

@@ -1,42 +1,62 @@
import { Deluge } from '@ctrl/deluge'; import { Deluge } from '@ctrl/deluge';
import { QBittorrent } from '@ctrl/qbittorrent'; import { QBittorrent } from '@ctrl/qbittorrent';
import { NormalizedTorrent } from '@ctrl/shared-torrent';
import { Transmission } from '@ctrl/transmission';
import { NextApiRequest, NextApiResponse } from 'next'; import { NextApiRequest, NextApiResponse } from 'next';
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 { dlclient } = req.query; const torrents: NormalizedTorrent[] = [];
const { body } = req; const { config }: { config: Config } = req.body;
// Get login, password and url from the body const qBittorrentService = config.services
const { username, password, url } = body; .filter((service) => service.type === 'qBittorrent')
if (!dlclient || (!username && !password) || !url) { .at(0);
return res.status(400).json({ const delugeService = config.services.filter((service) => service.type === 'Deluge').at(0);
error: 'Wrong request', const transmissionService = config.services
.filter((service) => service.type === 'Transmission')
.at(0);
if (!qBittorrentService && !delugeService && !transmissionService) {
return res.status(500).json({
statusCode: 500,
message: 'Missing service',
}); });
} }
let client: Deluge | QBittorrent; if (qBittorrentService) {
switch (dlclient) { torrents.push(
case 'qbit': ...(
client = new QBittorrent({ await new QBittorrent({
baseUrl: new URL(url).href, baseUrl: qBittorrentService.url,
username, username: qBittorrentService.username,
password, password: qBittorrentService.password,
}); }).getAllData()
break; ).torrents
case 'deluge': );
client = new Deluge({
baseUrl: new URL(url).href,
password,
});
break;
default:
return res.status(400).json({
error: 'Wrong request',
});
} }
const data = await client.getAllData(); if (delugeService) {
res.status(200).json({ const delugeTorrents = (
torrents: data.torrents, await new Deluge({
}); baseUrl: delugeService.url,
username: delugeService.username,
password: delugeService.password,
}).getAllData()
).torrents;
delugeTorrents.forEach((delugeTorrent) =>
torrents.push({ ...delugeTorrent, progress: delugeTorrent.progress / 100 })
);
}
if (transmissionService) {
torrents.push(
...(
await new Transmission({
baseUrl: transmissionService.url,
username: transmissionService.username,
password: transmissionService.password,
}).getAllData()
).torrents
);
}
res.status(200).json(torrents);
} }
export default async (req: NextApiRequest, res: NextApiResponse) => { export default async (req: NextApiRequest, res: NextApiResponse) => {

View File

@@ -31,6 +31,7 @@ export const ServiceTypeList = [
'Readarr', 'Readarr',
'Sonarr', 'Sonarr',
'qBittorrent', 'qBittorrent',
'Transmission',
]; ];
export type ServiceType = export type ServiceType =
| 'Other' | 'Other'
@@ -41,7 +42,8 @@ export type ServiceType =
| 'Radarr' | 'Radarr'
| 'Readarr' | 'Readarr'
| 'Sonarr' | 'Sonarr'
| 'qBittorrent'; | 'qBittorrent'
| 'Transmission';
export interface serviceItem { export interface serviceItem {
id: string; id: string;

View File

@@ -1630,6 +1630,15 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"@ctrl/shared-torrent@npm:^4.1.1":
version: 4.1.1
resolution: "@ctrl/shared-torrent@npm:4.1.1"
dependencies:
got: ^12.1.0
checksum: 1273c9088a920eed5afca945b11e83a6b64d4268ad0b09e916e7e2214ea8092b998ab16525885f8f24af2c75893e3fd7d4542e7e9d6dfe4688da57e47c31b165
languageName: node
linkType: hard
"@ctrl/torrent-file@npm:^2.0.1": "@ctrl/torrent-file@npm:^2.0.1":
version: 2.0.1 version: 2.0.1
resolution: "@ctrl/torrent-file@npm:2.0.1" resolution: "@ctrl/torrent-file@npm:2.0.1"
@@ -1639,6 +1648,18 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"@ctrl/transmission@npm:^4.1.1":
version: 4.1.1
resolution: "@ctrl/transmission@npm:4.1.1"
dependencies:
"@ctrl/magnet-link": ^3.1.0
"@ctrl/shared-torrent": ^4.1.1
"@ctrl/url-join": ^2.0.0
got: ^12.1.0
checksum: 218ed4c00f70c46c90cd2a5e90f8390beee06a2cf7d76c2445ad2bcfb89ad1e6ea9cf237a7b3aa990fdf81fc9b9d4aa9900fa21e041457e8bb177dbd0b319b0a
languageName: node
linkType: hard
"@ctrl/ts-base32@npm:^2.1.1": "@ctrl/ts-base32@npm:^2.1.1":
version: 2.1.1 version: 2.1.1
resolution: "@ctrl/ts-base32@npm:2.1.1" resolution: "@ctrl/ts-base32@npm:2.1.1"
@@ -9081,7 +9102,7 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"got@npm:^12.0.1, got@npm:^12.0.4": "got@npm:^12.0.1, got@npm:^12.0.4, got@npm:^12.1.0":
version: 12.1.0 version: 12.1.0
resolution: "got@npm:12.1.0" resolution: "got@npm:12.1.0"
dependencies: dependencies:
@@ -9398,6 +9419,7 @@ __metadata:
"@ctrl/deluge": ^4.0.0 "@ctrl/deluge": ^4.0.0
"@ctrl/qbittorrent": ^4.0.0 "@ctrl/qbittorrent": ^4.0.0
"@ctrl/shared-torrent": ^4.1.0 "@ctrl/shared-torrent": ^4.1.0
"@ctrl/transmission": ^4.1.1
"@dnd-kit/core": ^6.0.1 "@dnd-kit/core": ^6.0.1
"@dnd-kit/sortable": ^7.0.0 "@dnd-kit/sortable": ^7.0.0
"@dnd-kit/utilities": ^3.2.0 "@dnd-kit/utilities": ^3.2.0