mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-12 16:35:49 +01:00
✨Add useNet tile
This commit is contained in:
@@ -3,11 +3,11 @@ import dayjs from 'dayjs';
|
||||
import duration from 'dayjs/plugin/duration';
|
||||
import { NextApiRequest, NextApiResponse } from 'next';
|
||||
import { Client } from 'sabnzbd-api';
|
||||
import { getConfig } from '../../../../tools/getConfig';
|
||||
import { getServiceById } from '../../../../tools/hooks/useGetServiceByType';
|
||||
import { Config } from '../../../../tools/types';
|
||||
import { NzbgetStatus } from './nzbget/types';
|
||||
import { NzbgetClient } from './nzbget/nzbget-client';
|
||||
import { getConfig } from '../../../../tools/config/getConfig';
|
||||
|
||||
dayjs.extend(duration);
|
||||
|
||||
@@ -25,24 +25,24 @@ export interface UsenetInfoResponse {
|
||||
async function Get(req: NextApiRequest, res: NextApiResponse) {
|
||||
try {
|
||||
const configName = getCookie('config-name', { req });
|
||||
const { config }: { config: Config } = getConfig(configName?.toString() ?? 'default').props;
|
||||
const config = getConfig(configName?.toString() ?? 'default');
|
||||
const { serviceId } = req.query as any as UsenetInfoRequestParams;
|
||||
|
||||
const service = getServiceById(config, serviceId);
|
||||
const service = config.services.find((x) => x.id === serviceId);
|
||||
|
||||
if (!service) {
|
||||
throw new Error(`Service with ID "${req.query.serviceId}" could not be found.`);
|
||||
}
|
||||
|
||||
let response: UsenetInfoResponse;
|
||||
switch (service.type) {
|
||||
case 'NZBGet': {
|
||||
switch (service.integration?.type) {
|
||||
case 'nzbGet': {
|
||||
const url = new URL(service.url);
|
||||
const options = {
|
||||
host: url.hostname,
|
||||
port: url.port,
|
||||
login: service.username,
|
||||
hash: service.password,
|
||||
login: service.integration.properties.username,
|
||||
hash: service.integration.properties.password,
|
||||
};
|
||||
|
||||
const nzbGet = NzbgetClient(options);
|
||||
@@ -71,14 +71,14 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
|
||||
};
|
||||
break;
|
||||
}
|
||||
case 'Sabnzbd': {
|
||||
if (!service.apiKey) {
|
||||
case 'sabnzbd': {
|
||||
if (!service.integration.properties.apiKey) {
|
||||
throw new Error(`API Key for service "${service.name}" is missing`);
|
||||
}
|
||||
|
||||
const { origin } = new URL(service.url);
|
||||
|
||||
const queue = await new Client(origin, service.apiKey).queue(0, -1);
|
||||
const queue = await new Client(origin, service.integration.properties.apiKey).queue(0, -1);
|
||||
|
||||
const [hours, minutes, seconds] = queue.timeleft.split(':');
|
||||
const eta = dayjs.duration({
|
||||
@@ -96,7 +96,7 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new Error(`Service type "${service.type}" unrecognized.`);
|
||||
throw new Error(`Service type "${service.integration?.type}" unrecognized.`);
|
||||
}
|
||||
|
||||
return res.status(200).json(response);
|
||||
|
||||
Reference in New Issue
Block a user