mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-10 23:45:48 +01:00
✨Add useNet tile
This commit is contained in:
@@ -4,11 +4,11 @@ import duration from 'dayjs/plugin/duration';
|
||||
import { NextApiRequest, NextApiResponse } from 'next';
|
||||
import { Client } from 'sabnzbd-api';
|
||||
import { UsenetHistoryItem } from '../../../../modules';
|
||||
import { getConfig } from '../../../../tools/getConfig';
|
||||
import { getServiceById } from '../../../../tools/hooks/useGetServiceByType';
|
||||
import { Config } from '../../../../tools/types';
|
||||
import { NzbgetHistoryItem } from './nzbget/types';
|
||||
import { NzbgetClient } from './nzbget/nzbget-client';
|
||||
import { getConfig } from '../../../../tools/config/getConfig';
|
||||
|
||||
dayjs.extend(duration);
|
||||
|
||||
@@ -26,24 +26,24 @@ export interface UsenetHistoryResponse {
|
||||
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 { limit, offset, serviceId } = req.query as any as UsenetHistoryRequestParams;
|
||||
|
||||
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: UsenetHistoryResponse;
|
||||
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);
|
||||
@@ -76,14 +76,17 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
|
||||
};
|
||||
break;
|
||||
}
|
||||
case 'Sabnzbd': {
|
||||
case 'sabnzbd': {
|
||||
const { origin } = new URL(service.url);
|
||||
|
||||
if (!service.apiKey) {
|
||||
if (!service.integration.properties.apiKey) {
|
||||
throw new Error(`API Key for service "${service.name}" is missing`);
|
||||
}
|
||||
|
||||
const history = await new Client(origin, service.apiKey).history(offset, limit);
|
||||
const history = await new Client(origin, service.integration.properties.apiKey).history(
|
||||
offset,
|
||||
limit
|
||||
);
|
||||
|
||||
const items: UsenetHistoryItem[] = history.slots.map((slot) => ({
|
||||
id: slot.nzo_id,
|
||||
@@ -99,7 +102,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