🐛 Fix mismatched torrent clients

This commit is contained in:
Manuel
2023-01-30 12:51:54 +01:00
parent 1ffd984eb3
commit 1977c7478e
2 changed files with 13 additions and 4 deletions

View File

@@ -1,4 +1,6 @@
import { Deluge } from '@ctrl/deluge'; import { Deluge } from '@ctrl/deluge';
import { QBittorrent } from '@ctrl/qbittorrent';
import { Transmission } from '@ctrl/transmission';
import { AllClientData } from '@ctrl/shared-torrent'; import { AllClientData } from '@ctrl/shared-torrent';
import Consola from 'consola'; import Consola from 'consola';
import { getCookie } from 'cookies-next'; import { getCookie } from 'cookies-next';
@@ -32,7 +34,7 @@ const Get = async (request: NextApiRequest, response: NextApiResponse) => {
} }
return response; return response;
} catch (err) { } catch (err: any) {
Consola.error( Consola.error(
`Error communicating with your download client '${app.name}' (${app.id}): ${err}` `Error communicating with your download client '${app.name}' (${app.id}): ${err}`
); );
@@ -50,7 +52,11 @@ const Get = async (request: NextApiRequest, response: NextApiResponse) => {
.map((promise) => (promise as PromiseFulfilledResult<NormalizedDownloadAppStat>).value) .map((promise) => (promise as PromiseFulfilledResult<NormalizedDownloadAppStat>).value)
.filter((x) => x !== undefined && x.type !== undefined); .filter((x) => x !== undefined && x.type !== undefined);
const responseBody = { apps: data } as NormalizedDownloadQueueResponse; const responseBody = { apps: data, failedApps: failedClients } as NormalizedDownloadQueueResponse;
if (failedClients.length > 0) {
Consola.warn(`${failedClients.length} download clients failed. Please check your configuration and the above log`);
}
return response.status(200).json(responseBody); return response.status(200).json(responseBody);
}; };
@@ -85,7 +91,7 @@ const GetDataFromClient = async (
} }
case 'transmission': { case 'transmission': {
return reduceTorrent( return reduceTorrent(
await new Deluge({ await new Transmission({
baseUrl: app.url, baseUrl: app.url,
username: findField(app, 'username'), username: findField(app, 'username'),
password: findField(app, 'password'), password: findField(app, 'password'),
@@ -94,7 +100,7 @@ const GetDataFromClient = async (
} }
case 'qBittorrent': { case 'qBittorrent': {
return reduceTorrent( return reduceTorrent(
await new Deluge({ await new QBittorrent({
baseUrl: app.url, baseUrl: app.url,
username: findField(app, 'username'), username: findField(app, 'username'),
password: findField(app, 'password'), password: findField(app, 'password'),
@@ -147,6 +153,7 @@ const GetDataFromClient = async (
if (!err) { if (!err) {
resolve(result); resolve(result);
} else { } else {
Consola.error(`Error while listing groups: ${err}`);
reject(err); reject(err);
} }
}); });
@@ -160,6 +167,7 @@ const GetDataFromClient = async (
if (!err) { if (!err) {
resolve(result); resolve(result);
} else { } else {
Consola.error(`Error while retrieving NZBGet stats: ${err}`);
reject(err); reject(err);
} }
}); });

View File

@@ -3,6 +3,7 @@ import { UsenetQueueItem } from '../../../../widgets/useNet/types';
export type NormalizedDownloadQueueResponse = { export type NormalizedDownloadQueueResponse = {
apps: NormalizedDownloadAppStat[]; apps: NormalizedDownloadAppStat[];
failedApps: string[];
}; };
export type NormalizedDownloadAppStat = { export type NormalizedDownloadAppStat = {