Add improved torrent network traffic widget

This commit is contained in:
Meierschlumpf
2022-12-21 20:29:09 +01:00
parent 8e9f9d23b3
commit 6cf6d9c2f5
2 changed files with 19 additions and 20 deletions

View File

@@ -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))

View File

@@ -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,
}); });