mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-11 16:05:47 +01:00
✨ Add improved torrent network traffic widget
This commit is contained in:
@@ -4,16 +4,15 @@ import { NormalizedTorrent } from '@ctrl/shared-torrent';
|
|||||||
import { Transmission } from '@ctrl/transmission';
|
import { Transmission } from '@ctrl/transmission';
|
||||||
import { getCookie } from 'cookies-next';
|
import { getCookie } from 'cookies-next';
|
||||||
import { NextApiRequest, NextApiResponse } from 'next';
|
import { NextApiRequest, NextApiResponse } from 'next';
|
||||||
import { getConfig } from '../../../tools/getConfig';
|
import { getConfig } from '../../../tools/config/getConfig';
|
||||||
import { Config } from '../../../tools/types';
|
|
||||||
|
|
||||||
async function Post(req: NextApiRequest, res: NextApiResponse) {
|
async function Post(req: NextApiRequest, res: NextApiResponse) {
|
||||||
// Get the type of app from the request url
|
// Get the type of app from the request url
|
||||||
const configName = getCookie('config-name', { req });
|
const configName = getCookie('config-name', { req });
|
||||||
const { config }: { config: Config } = getConfig(configName?.toString() ?? 'default').props;
|
const config = getConfig(configName?.toString() ?? 'default');
|
||||||
const qBittorrentApp = config.apps.filter((app) => app.type === 'qBittorrent');
|
const qBittorrentApp = config.apps.filter((app) => app.integration?.type === 'qBittorrent');
|
||||||
const delugeApp = config.apps.filter((app) => app.type === 'Deluge');
|
const delugeApp = config.apps.filter((app) => app.integration?.type === 'deluge');
|
||||||
const transmissionApp = config.apps.filter((app) => app.type === 'Transmission');
|
const transmissionApp = config.apps.filter((app) => app.integration?.type === 'transmission');
|
||||||
|
|
||||||
const torrents: NormalizedTorrent[] = [];
|
const torrents: NormalizedTorrent[] = [];
|
||||||
|
|
||||||
@@ -25,21 +24,21 @@ async function Post(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
qBittorrentApp.map((apps) =>
|
qBittorrentApp.map((app) =>
|
||||||
new QBittorrent({
|
new QBittorrent({
|
||||||
baseUrl: apps.url,
|
baseUrl: app.url,
|
||||||
username: apps.username,
|
username: app.integration!.properties.find((x) => x.field === 'username')?.value,
|
||||||
password: apps.password,
|
password: app.integration!.properties.find((x) => x.field === 'password')?.value,
|
||||||
})
|
})
|
||||||
.getAllData()
|
.getAllData()
|
||||||
.then((e) => torrents.push(...e.torrents))
|
.then((e) => torrents.push(...e.torrents))
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
delugeApp.map((apps) =>
|
delugeApp.map((app) =>
|
||||||
new Deluge({
|
new Deluge({
|
||||||
baseUrl: apps.url,
|
baseUrl: app.url,
|
||||||
password: 'password' in apps ? apps.password : '',
|
password: app.integration!.properties.find((x) => x.field === 'password')?.value,
|
||||||
})
|
})
|
||||||
.getAllData()
|
.getAllData()
|
||||||
.then((e) => torrents.push(...e.torrents))
|
.then((e) => torrents.push(...e.torrents))
|
||||||
@@ -47,11 +46,11 @@ async function Post(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
);
|
);
|
||||||
// Map transmissionApps
|
// Map transmissionApps
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
transmissionApp.map((apps) =>
|
transmissionApp.map((app) =>
|
||||||
new Transmission({
|
new Transmission({
|
||||||
baseUrl: apps.url,
|
baseUrl: app.url,
|
||||||
username: 'username' in apps ? apps.username : '',
|
username: app.integration!.properties.find((x) => x.field === 'username')?.value,
|
||||||
password: 'password' in apps ? apps.password : '',
|
password: app.integration!.properties.find((x) => x.field === 'password')?.value,
|
||||||
})
|
})
|
||||||
.getAllData()
|
.getAllData()
|
||||||
.then((e) => torrents.push(...e.torrents))
|
.then((e) => torrents.push(...e.torrents))
|
||||||
|
|||||||
@@ -20,10 +20,10 @@ const definition = defineWidget({
|
|||||||
options: {},
|
options: {},
|
||||||
|
|
||||||
gridstack: {
|
gridstack: {
|
||||||
minWidth: 4,
|
minWidth: 6,
|
||||||
minHeight: 4,
|
minHeight: 6,
|
||||||
maxWidth: 12,
|
maxWidth: 12,
|
||||||
maxHeight: 12,
|
maxHeight: 6,
|
||||||
},
|
},
|
||||||
component: TorrentNetworkTrafficTile,
|
component: TorrentNetworkTrafficTile,
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user